effect 4.0.0-beta.6 → 4.0.0-beta.8
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/Cache.d.ts +2 -2
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cache.js.map +1 -1
- package/dist/Combiner.d.ts +280 -13
- package/dist/Combiner.d.ts.map +1 -1
- package/dist/Combiner.js +198 -7
- package/dist/Combiner.js.map +1 -1
- package/dist/Config.d.ts +2 -2
- package/dist/Config.js +3 -3
- package/dist/Config.js.map +1 -1
- package/dist/DateTime.d.ts +23 -161
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +6 -51
- package/dist/DateTime.js.map +1 -1
- package/dist/Duration.d.ts +12 -12
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +12 -12
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +13 -13
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +1 -1
- package/dist/Effect.js.map +1 -1
- package/dist/Formatter.d.ts +131 -47
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +228 -50
- package/dist/Formatter.js.map +1 -1
- package/dist/JsonSchema.d.ts +299 -10
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +323 -4
- package/dist/JsonSchema.js.map +1 -1
- package/dist/LayerMap.d.ts +4 -4
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LogLevel.d.ts +27 -0
- package/dist/LogLevel.d.ts.map +1 -1
- package/dist/LogLevel.js +28 -100
- package/dist/LogLevel.js.map +1 -1
- package/dist/Logger.d.ts +4 -4
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Metric.d.ts +2 -2
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +1 -1
- package/dist/Metric.js.map +1 -1
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +1 -1
- package/dist/Pool.js.map +1 -1
- package/dist/Random.d.ts +1 -1
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +3 -12
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts +2 -2
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +1 -1
- package/dist/RcMap.js.map +1 -1
- package/dist/RcRef.d.ts +1 -1
- package/dist/RcRef.d.ts.map +1 -1
- package/dist/Reducer.d.ts +166 -7
- package/dist/Reducer.d.ts.map +1 -1
- package/dist/Reducer.js +135 -1
- package/dist/Reducer.js.map +1 -1
- package/dist/RequestResolver.d.ts +6 -6
- package/dist/RequestResolver.d.ts.map +1 -1
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Schedule.d.ts +20 -11
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +23 -9
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +4 -4
- package/dist/Schema.d.ts.map +1 -1
- package/dist/ScopedCache.d.ts +2 -2
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +19 -19
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +3 -3
- package/dist/Stream.js.map +1 -1
- package/dist/index.d.ts +258 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +258 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/dateTime.js +3 -11
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +2 -2
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/random.d.ts +2 -0
- package/dist/internal/random.d.ts.map +1 -0
- package/dist/internal/random.js +13 -0
- package/dist/internal/random.js.map +1 -0
- package/dist/internal/rcRef.js +1 -1
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/testing/TestClock.d.ts +4 -4
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +1 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +6 -6
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +10 -10
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +3 -3
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +2 -2
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +2 -2
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +17 -17
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Response.d.ts +23 -23
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterCron.js +1 -1
- package/dist/unstable/cluster/ClusterCron.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +3 -3
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityResource.d.ts +2 -2
- package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +1 -1
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +21 -21
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +1 -1
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +2 -2
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/http/Cookies.d.ts +1 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +2 -2
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +4 -4
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +11 -11
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +8 -1
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpMethod.d.ts +4 -4
- package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
- package/dist/unstable/http/HttpMethod.js +3 -3
- package/dist/unstable/http/HttpMethod.js.map +1 -1
- package/dist/unstable/observability/Otlp.d.ts +12 -12
- package/dist/unstable/observability/Otlp.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +1 -1
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +2 -2
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +6 -6
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +1 -1
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +2 -2
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +1 -1
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +2 -2
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +6 -6
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +3 -3
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +1 -1
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +2 -2
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +5 -26
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +3 -11
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +4 -4
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.d.ts +2 -2
- package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.js +3 -3
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +16 -5
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/SqlSchema.js +17 -7
- package/dist/unstable/sql/SqlSchema.js.map +1 -1
- package/dist/unstable/workflow/DurableClock.d.ts +3 -3
- package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableClock.js +3 -3
- package/dist/unstable/workflow/DurableClock.js.map +1 -1
- package/package.json +1 -1
- package/src/Cache.ts +3 -3
- package/src/Combiner.ts +280 -13
- package/src/Config.ts +3 -3
- package/src/DateTime.ts +24 -164
- package/src/Duration.ts +15 -15
- package/src/Effect.ts +15 -15
- package/src/Formatter.ts +252 -50
- package/src/JsonSchema.ts +383 -10
- package/src/LayerMap.ts +5 -5
- package/src/LogLevel.ts +31 -0
- package/src/Logger.ts +5 -5
- package/src/Metric.ts +4 -4
- package/src/Pool.ts +4 -4
- package/src/Random.ts +5 -14
- package/src/RcMap.ts +5 -5
- package/src/RcRef.ts +1 -1
- package/src/Reducer.ts +166 -7
- package/src/RequestResolver.ts +9 -9
- package/src/Schedule.ts +44 -25
- package/src/Schema.ts +4 -4
- package/src/ScopedCache.ts +3 -3
- package/src/Stream.ts +34 -34
- package/src/index.ts +258 -0
- package/src/internal/dateTime.ts +9 -30
- package/src/internal/effect.ts +21 -21
- package/src/internal/random.ts +20 -0
- package/src/internal/rcRef.ts +2 -2
- package/src/testing/TestClock.ts +5 -5
- package/src/testing/TestSchema.ts +8 -8
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/Chat.ts +10 -10
- package/src/unstable/ai/LanguageModel.ts +3 -3
- package/src/unstable/ai/McpServer.ts +2 -2
- package/src/unstable/ai/Prompt.ts +17 -17
- package/src/unstable/ai/Response.ts +23 -23
- package/src/unstable/cluster/ClusterCron.ts +2 -2
- package/src/unstable/cluster/Entity.ts +5 -5
- package/src/unstable/cluster/EntityResource.ts +4 -4
- package/src/unstable/cluster/K8sHttpClient.ts +1 -1
- package/src/unstable/cluster/MessageStorage.ts +1 -4
- package/src/unstable/cluster/Sharding.ts +3 -3
- package/src/unstable/cluster/ShardingConfig.ts +10 -11
- package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +3 -3
- package/src/unstable/encoding/Sse.ts +2 -4
- package/src/unstable/http/Cookies.ts +3 -3
- package/src/unstable/http/HttpClient.ts +4 -4
- package/src/unstable/http/HttpClientRequest.ts +15 -11
- package/src/unstable/http/HttpMethod.ts +16 -4
- package/src/unstable/observability/Otlp.ts +12 -12
- package/src/unstable/observability/OtlpExporter.ts +3 -3
- package/src/unstable/observability/OtlpLogger.ts +4 -4
- package/src/unstable/observability/OtlpMetrics.ts +4 -4
- package/src/unstable/observability/OtlpTracer.ts +4 -4
- package/src/unstable/persistence/Persistable.ts +2 -2
- package/src/unstable/persistence/PersistedQueue.ts +18 -18
- package/src/unstable/persistence/Persistence.ts +3 -3
- package/src/unstable/persistence/RateLimiter.ts +4 -4
- package/src/unstable/process/ChildProcess.ts +2 -2
- package/src/unstable/reactivity/Atom.ts +13 -13
- package/src/unstable/reactivity/AtomHttpApi.ts +3 -3
- package/src/unstable/reactivity/AtomRpc.ts +3 -3
- package/src/unstable/rpc/Rpc.ts +3 -3
- package/src/unstable/rpc/RpcClient.ts +8 -51
- package/src/unstable/socket/Socket.ts +4 -4
- package/src/unstable/sql/SqlModel.ts +5 -5
- package/src/unstable/sql/SqlSchema.ts +41 -25
- package/src/unstable/workflow/DurableClock.ts +8 -8
package/dist/Formatter.js
CHANGED
|
@@ -1,4 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Utilities for converting arbitrary JavaScript values into human-readable
|
|
3
|
+
* strings, with support for circular references, redaction, and common JS
|
|
4
|
+
* types that `JSON.stringify` handles poorly.
|
|
5
|
+
*
|
|
6
|
+
* Mental model:
|
|
7
|
+
* - A `Formatter<Value, Format>` is a callable `(value: Value) => Format`.
|
|
8
|
+
* - {@link format} is the general-purpose pretty-printer: it handles
|
|
9
|
+
* primitives, arrays, objects, `BigInt`, `Symbol`, `Date`, `RegExp`,
|
|
10
|
+
* `Set`, `Map`, class instances, and circular references.
|
|
11
|
+
* - {@link formatJson} is a safe `JSON.stringify` wrapper that silently
|
|
12
|
+
* drops circular references and applies redaction.
|
|
13
|
+
* - Both functions accept a `space` option for indentation control.
|
|
14
|
+
*
|
|
15
|
+
* Common tasks:
|
|
16
|
+
* - Pretty-print any value for debugging / logging -> {@link format}
|
|
17
|
+
* - Serialize to JSON safely (no circular throws) -> {@link formatJson}
|
|
18
|
+
* - Format a single object property key -> {@link formatPropertyKey}
|
|
19
|
+
* - Format a property path like `["a"]["b"]` -> {@link formatPath}
|
|
20
|
+
* - Format a `Date` to ISO string safely -> {@link formatDate}
|
|
21
|
+
*
|
|
22
|
+
* Gotchas:
|
|
23
|
+
* - {@link format} output is **not** valid JSON; use {@link formatJson} when
|
|
24
|
+
* you need parseable JSON.
|
|
25
|
+
* - {@link format} calls `toString()` on objects by default; pass
|
|
26
|
+
* `ignoreToString: true` to disable.
|
|
27
|
+
* - {@link formatJson} silently omits circular references (the key is
|
|
28
|
+
* dropped from the output).
|
|
29
|
+
* - Values implementing the `Redactable` protocol are automatically
|
|
30
|
+
* redacted by both {@link format} and {@link formatJson}.
|
|
31
|
+
*
|
|
32
|
+
* **Example** (Pretty-print a value)
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { Formatter } from "effect"
|
|
36
|
+
*
|
|
37
|
+
* const obj = { name: "Alice", scores: [100, 97] }
|
|
38
|
+
* console.log(Formatter.format(obj))
|
|
39
|
+
* // {"name":"Alice","scores":[100,97]}
|
|
40
|
+
*
|
|
41
|
+
* console.log(Formatter.format(obj, { space: 2 }))
|
|
42
|
+
* // {
|
|
43
|
+
* // "name": "Alice",
|
|
44
|
+
* // "scores": [
|
|
45
|
+
* // 100,
|
|
46
|
+
* // 97
|
|
47
|
+
* // ]
|
|
48
|
+
* // }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* See also: {@link Formatter}, {@link format}, {@link formatJson}
|
|
52
|
+
*
|
|
2
53
|
* @since 4.0.0
|
|
3
54
|
*/
|
|
4
55
|
import * as Predicate from "./Predicate.js";
|
|
@@ -6,31 +57,71 @@ import { getRedacted, redact, symbolRedactable } from "./Redactable.js";
|
|
|
6
57
|
/**
|
|
7
58
|
* Converts any JavaScript value into a human-readable string.
|
|
8
59
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* - Does not
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* - Primitives
|
|
21
|
-
*
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* -
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
60
|
+
* When to use:
|
|
61
|
+
* - Pretty-printing values for debugging, logging, or error messages.
|
|
62
|
+
* - You need to handle `BigInt`, `Symbol`, `Set`, `Map`, `Date`, `RegExp`,
|
|
63
|
+
* or class instances that `JSON.stringify` cannot represent.
|
|
64
|
+
* - You want circular references shown as `"[Circular]"` instead of
|
|
65
|
+
* throwing.
|
|
66
|
+
*
|
|
67
|
+
* Behavior:
|
|
68
|
+
* - Does not mutate input.
|
|
69
|
+
* - Output is **not** valid JSON; use {@link formatJson} when you need
|
|
70
|
+
* parseable JSON.
|
|
71
|
+
* - Primitives: stringified naturally (`null`, `undefined`, `123`, `true`).
|
|
72
|
+
* Strings are JSON-quoted.
|
|
73
|
+
* - Objects with a custom `toString` (not `Object.prototype.toString`):
|
|
74
|
+
* `toString()` is called unless `ignoreToString` is `true`.
|
|
75
|
+
* - Errors with a `cause`: formatted as `"<message> (cause: <cause>)"`.
|
|
76
|
+
* - Iterables (`Set`, `Map`, etc.): formatted as
|
|
77
|
+
* `ClassName([...elements])`.
|
|
78
|
+
* - Class instances: wrapped as `ClassName({...})`.
|
|
79
|
+
* - `Redactable` values are automatically redacted.
|
|
80
|
+
* - Arrays/objects with 0–1 entries are inline; larger ones are
|
|
81
|
+
* pretty-printed when `space` is set.
|
|
82
|
+
* - Circular references are replaced with `"[Circular]"`.
|
|
83
|
+
*
|
|
84
|
+
* Options:
|
|
85
|
+
* - `space` — indentation unit (number of spaces, or a string like
|
|
86
|
+
* `"\t"`). Defaults to `0` (compact).
|
|
87
|
+
* - `ignoreToString` — skip calling `toString()`. Defaults to `false`.
|
|
88
|
+
*
|
|
89
|
+
* **Example** (Compact output)
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { Formatter } from "effect"
|
|
93
|
+
*
|
|
94
|
+
* console.log(Formatter.format({ a: 1, b: [2, 3] }))
|
|
95
|
+
* // {"a":1,"b":[2,3]}
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* **Example** (Pretty-printed output)
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { Formatter } from "effect"
|
|
102
|
+
*
|
|
103
|
+
* console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
|
|
104
|
+
* // {
|
|
105
|
+
* // "a": 1,
|
|
106
|
+
* // "b": [
|
|
107
|
+
* // 2,
|
|
108
|
+
* // 3
|
|
109
|
+
* // ]
|
|
110
|
+
* // }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* **Example** (Circular reference handling)
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { Formatter } from "effect"
|
|
117
|
+
*
|
|
118
|
+
* const obj: any = { name: "loop" }
|
|
119
|
+
* obj.self = obj
|
|
120
|
+
* console.log(Formatter.format(obj))
|
|
121
|
+
* // {"name":"loop","self":[Circular]}
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* See also: {@link formatJson}, {@link Formatter}
|
|
34
125
|
*
|
|
35
126
|
* @since 4.0.0
|
|
36
127
|
*/
|
|
@@ -90,7 +181,29 @@ export function format(input, options) {
|
|
|
90
181
|
}
|
|
91
182
|
const CIRCULAR = "[Circular]";
|
|
92
183
|
/**
|
|
93
|
-
*
|
|
184
|
+
* Formats a single property key for display.
|
|
185
|
+
*
|
|
186
|
+
* When to use:
|
|
187
|
+
* - You are building a custom formatter that needs to render object keys.
|
|
188
|
+
*
|
|
189
|
+
* Behavior:
|
|
190
|
+
* - String keys are JSON-quoted (e.g. `"foo"`).
|
|
191
|
+
* - Symbol and number keys are converted with `String()`.
|
|
192
|
+
* - Pure function; does not mutate input.
|
|
193
|
+
*
|
|
194
|
+
* **Example** (Format property keys)
|
|
195
|
+
*
|
|
196
|
+
* ```ts
|
|
197
|
+
* import { Formatter } from "effect"
|
|
198
|
+
*
|
|
199
|
+
* console.log(Formatter.formatPropertyKey("name"))
|
|
200
|
+
* // "name"
|
|
201
|
+
*
|
|
202
|
+
* console.log(Formatter.formatPropertyKey(Symbol.for("id")))
|
|
203
|
+
* // Symbol(id)
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* See also: {@link formatPath}, {@link format}
|
|
94
207
|
*
|
|
95
208
|
* @internal
|
|
96
209
|
*/
|
|
@@ -98,7 +211,28 @@ export function formatPropertyKey(name) {
|
|
|
98
211
|
return typeof name === "string" ? JSON.stringify(name) : String(name);
|
|
99
212
|
}
|
|
100
213
|
/**
|
|
101
|
-
*
|
|
214
|
+
* Formats an array of property keys as a bracket-notation path string.
|
|
215
|
+
*
|
|
216
|
+
* When to use:
|
|
217
|
+
* - You need to display a path through a nested object (e.g. in error
|
|
218
|
+
* messages or schema validation output).
|
|
219
|
+
*
|
|
220
|
+
* Behavior:
|
|
221
|
+
* - Each key is wrapped in brackets and formatted via
|
|
222
|
+
* {@link formatPropertyKey}.
|
|
223
|
+
* - Returns an empty string for an empty path.
|
|
224
|
+
* - Pure function; does not mutate input.
|
|
225
|
+
*
|
|
226
|
+
* **Example** (Render a property path)
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { Formatter } from "effect"
|
|
230
|
+
*
|
|
231
|
+
* console.log(Formatter.formatPath(["users", 0, "name"]))
|
|
232
|
+
* // ["users"][0]["name"]
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* See also: {@link formatPropertyKey}, {@link format}
|
|
102
236
|
*
|
|
103
237
|
* @internal
|
|
104
238
|
*/
|
|
@@ -106,7 +240,31 @@ export function formatPath(path) {
|
|
|
106
240
|
return path.map(key => `[${formatPropertyKey(key)}]`).join("");
|
|
107
241
|
}
|
|
108
242
|
/**
|
|
109
|
-
*
|
|
243
|
+
* Formats a `Date` as an ISO 8601 string, returning `"Invalid Date"` for
|
|
244
|
+
* invalid dates instead of throwing.
|
|
245
|
+
*
|
|
246
|
+
* When to use:
|
|
247
|
+
* - You want a safe `toISOString()` that never throws.
|
|
248
|
+
*
|
|
249
|
+
* Behavior:
|
|
250
|
+
* - Returns `date.toISOString()` on success.
|
|
251
|
+
* - Returns `"Invalid Date"` if `toISOString()` throws (e.g. for
|
|
252
|
+
* `new Date(NaN)`).
|
|
253
|
+
* - Pure function; does not mutate input.
|
|
254
|
+
*
|
|
255
|
+
* **Example** (Safe date formatting)
|
|
256
|
+
*
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { Formatter } from "effect"
|
|
259
|
+
*
|
|
260
|
+
* console.log(Formatter.formatDate(new Date("2024-01-15T10:30:00Z")))
|
|
261
|
+
* // 2024-01-15T10:30:00.000Z
|
|
262
|
+
*
|
|
263
|
+
* console.log(Formatter.formatDate(new Date("invalid")))
|
|
264
|
+
* // Invalid Date
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* See also: {@link format}
|
|
110
268
|
*
|
|
111
269
|
* @internal
|
|
112
270
|
*/
|
|
@@ -126,42 +284,62 @@ function safeToString(input) {
|
|
|
126
284
|
}
|
|
127
285
|
}
|
|
128
286
|
/**
|
|
129
|
-
* Safely stringifies
|
|
287
|
+
* Safely stringifies a value to JSON, silently dropping circular references.
|
|
288
|
+
*
|
|
289
|
+
* When to use:
|
|
290
|
+
* - You need valid JSON output (unlike {@link format}).
|
|
291
|
+
* - The input may contain circular references and you want them silently
|
|
292
|
+
* omitted rather than throwing a `TypeError`.
|
|
130
293
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
294
|
+
* Behavior:
|
|
295
|
+
* - Does not mutate input.
|
|
296
|
+
* - Uses `JSON.stringify` internally with a replacer that tracks seen
|
|
297
|
+
* objects.
|
|
298
|
+
* - Circular references are replaced with `undefined` (omitted from
|
|
299
|
+
* output).
|
|
300
|
+
* - `Redactable` values are automatically redacted before serialization.
|
|
301
|
+
* - Types not supported by JSON (`BigInt`, `Symbol`, `undefined`,
|
|
302
|
+
* functions) follow standard `JSON.stringify` behavior (omitted or
|
|
303
|
+
* `null` in arrays).
|
|
134
304
|
*
|
|
135
|
-
*
|
|
136
|
-
* - `space
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* Defaults to `0`.
|
|
305
|
+
* Options:
|
|
306
|
+
* - `space` — indentation unit (number of spaces, or a string like
|
|
307
|
+
* `"\t"`). Defaults to `0` (compact).
|
|
308
|
+
*
|
|
309
|
+
* **Example** (Compact JSON)
|
|
141
310
|
*
|
|
142
|
-
* @example
|
|
143
311
|
* ```ts
|
|
144
|
-
* import {
|
|
312
|
+
* import { Formatter } from "effect"
|
|
145
313
|
*
|
|
146
|
-
*
|
|
147
|
-
* const simple = { name: "Alice", age: 30 }
|
|
148
|
-
* console.log(formatJson(simple))
|
|
314
|
+
* console.log(Formatter.formatJson({ name: "Alice", age: 30 }))
|
|
149
315
|
* // {"name":"Alice","age":30}
|
|
316
|
+
* ```
|
|
150
317
|
*
|
|
151
|
-
*
|
|
152
|
-
* const circular: any = { name: "test" }
|
|
153
|
-
* circular.self = circular
|
|
154
|
-
* console.log(formatJson(circular))
|
|
155
|
-
* // {"name":"test"} (circular reference omitted)
|
|
318
|
+
* **Example** (Circular reference handling)
|
|
156
319
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
320
|
+
* ```ts
|
|
321
|
+
* import { Formatter } from "effect"
|
|
322
|
+
*
|
|
323
|
+
* const obj: any = { name: "test" }
|
|
324
|
+
* obj.self = obj
|
|
325
|
+
* console.log(Formatter.formatJson(obj))
|
|
326
|
+
* // {"name":"test"}
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* **Example** (Pretty-printed JSON)
|
|
330
|
+
*
|
|
331
|
+
* ```ts
|
|
332
|
+
* import { Formatter } from "effect"
|
|
333
|
+
*
|
|
334
|
+
* console.log(Formatter.formatJson({ name: "Alice", age: 30 }, { space: 2 }))
|
|
159
335
|
* // {
|
|
160
336
|
* // "name": "Alice",
|
|
161
337
|
* // "age": 30
|
|
162
338
|
* // }
|
|
163
339
|
* ```
|
|
164
340
|
*
|
|
341
|
+
* See also: {@link format}, {@link Formatter}
|
|
342
|
+
*
|
|
165
343
|
* @since 4.0.0
|
|
166
344
|
*/
|
|
167
345
|
export function formatJson(input, options) {
|
package/dist/Formatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Formatter.js","names":["Predicate","getRedacted","redact","symbolRedactable","format","input","options","space","seen","WeakSet","gap","repeat","ind","d","wrap","v","body","ctor","constructor","Object","prototype","name","ownKeys","o","Reflect","recur","Array","isArray","has","CIRCULAR","add","length","map","x","join","inner","Date","formatDate","ignoreToString","hasProperty","toString","s","safeToString","Error","cause","JSON","stringify","String","Symbol","iterator","from","keys","k","formatPropertyKey","formatPath","path","key","date","toISOString","formatJson","cache","out","_key","value","includes","undefined","push"],"sources":["../src/Formatter.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Formatter.js","names":["Predicate","getRedacted","redact","symbolRedactable","format","input","options","space","seen","WeakSet","gap","repeat","ind","d","wrap","v","body","ctor","constructor","Object","prototype","name","ownKeys","o","Reflect","recur","Array","isArray","has","CIRCULAR","add","length","map","x","join","inner","Date","formatDate","ignoreToString","hasProperty","toString","s","safeToString","Error","cause","JSON","stringify","String","Symbol","iterator","from","keys","k","formatPropertyKey","formatPath","path","key","date","toISOString","formatJson","cache","out","_key","value","includes","undefined","push"],"sources":["../src/Formatter.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,OAAO,KAAKA,SAAS,MAAM,gBAAgB;AAC3C,SAASC,WAAW,EAAEC,MAAM,EAAEC,gBAAgB,QAAQ,iBAAiB;AAkCvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,OAAM,SAAUC,MAAMA,CAACC,KAAc,EAAEC,OAGtC;EACC,MAAMC,KAAK,GAAGD,OAAO,EAAEC,KAAK,IAAI,CAAC;EACjC,MAAMC,IAAI,GAAG,IAAIC,OAAO,EAAU;EAClC,MAAMC,GAAG,GAAG,CAACH,KAAK,GAAG,EAAE,GAAI,OAAOA,KAAK,KAAK,QAAQ,GAAG,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,GAAGA,KAAM;EACjF,MAAMK,GAAG,GAAIC,CAAS,IAAKH,GAAG,CAACC,MAAM,CAACE,CAAC,CAAC;EAExC,MAAMC,IAAI,GAAGA,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