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/JsonSchema.d.ts
CHANGED
|
@@ -1,29 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* A plain object representing a single JSON Schema node.
|
|
3
|
+
*
|
|
4
|
+
* This is an open record type (`[x: string]: unknown`) so it can hold any
|
|
5
|
+
* JSON Schema keyword. Most functions in this module accept or return this
|
|
6
|
+
* type.
|
|
7
|
+
*
|
|
2
8
|
* @since 4.0.0
|
|
3
9
|
*/
|
|
4
10
|
export interface JsonSchema {
|
|
5
11
|
[x: string]: unknown;
|
|
6
12
|
}
|
|
7
13
|
/**
|
|
14
|
+
* The set of JSON Schema dialects supported by this module.
|
|
15
|
+
*
|
|
16
|
+
* - `"draft-07"` — JSON Schema Draft-07
|
|
17
|
+
* - `"draft-2020-12"` — JSON Schema Draft 2020-12 (canonical internal form)
|
|
18
|
+
* - `"openapi-3.1"` — OpenAPI 3.1 (uses Draft 2020-12 as its schema dialect)
|
|
19
|
+
* - `"openapi-3.0"` — OpenAPI 3.0 (uses a Draft-04/07 subset with extensions)
|
|
20
|
+
*
|
|
8
21
|
* @since 4.0.0
|
|
9
22
|
*/
|
|
10
23
|
export type Dialect = "draft-07" | "draft-2020-12" | "openapi-3.1" | "openapi-3.0";
|
|
11
24
|
/**
|
|
25
|
+
* The JSON Schema primitive type names.
|
|
26
|
+
*
|
|
12
27
|
* @since 4.0.0
|
|
13
28
|
*/
|
|
14
29
|
export type Type = "string" | "number" | "boolean" | "array" | "object" | "null" | "integer";
|
|
15
30
|
/**
|
|
31
|
+
* A record of named JSON Schema definitions, keyed by definition name.
|
|
32
|
+
*
|
|
16
33
|
* @since 4.0.0
|
|
17
34
|
*/
|
|
18
35
|
export interface Definitions extends Record<string, JsonSchema> {
|
|
19
36
|
}
|
|
20
37
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
38
|
+
* A structured container for a single JSON Schema and its associated
|
|
39
|
+
* definitions.
|
|
40
|
+
*
|
|
41
|
+
* - Use when you need to carry a root schema together with its
|
|
42
|
+
* shared definitions.
|
|
43
|
+
* - Use when converting between dialects via the `from*` / `to*` functions.
|
|
44
|
+
*
|
|
45
|
+
* The `schema` field holds the root schema *without* the definitions
|
|
46
|
+
* collection. Root definitions are stored separately in `definitions` and
|
|
47
|
+
* referenced via:
|
|
48
|
+
* - `#/$defs/<name>` for Draft-2020-12
|
|
49
|
+
* - `#/definitions/<name>` for Draft-07
|
|
50
|
+
* - `#/components/schemas/<name>` for OpenAPI 3.1 and OpenAPI 3.0
|
|
51
|
+
*
|
|
52
|
+
* **Example** (Inspecting a parsed document)
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { JsonSchema } from "effect"
|
|
56
|
+
*
|
|
57
|
+
* const raw: JsonSchema.JsonSchema = {
|
|
58
|
+
* type: "string",
|
|
59
|
+
* $defs: { Trimmed: { type: "string", minLength: 1 } }
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* const doc = JsonSchema.fromSchemaDraft2020_12(raw)
|
|
63
|
+
*
|
|
64
|
+
* console.log(doc.dialect) // "draft-2020-12"
|
|
65
|
+
* console.log(doc.schema) // { type: "string" }
|
|
66
|
+
* console.log(doc.definitions) // { Trimmed: { type: "string", minLength: 1 } }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @see {@link MultiDocument}
|
|
70
|
+
* @see {@link fromSchemaDraft2020_12}
|
|
27
71
|
*
|
|
28
72
|
* @since 4.0.0
|
|
29
73
|
*/
|
|
@@ -33,6 +77,16 @@ export interface Document<D extends Dialect> {
|
|
|
33
77
|
readonly definitions: Definitions;
|
|
34
78
|
}
|
|
35
79
|
/**
|
|
80
|
+
* Like {@link Document}, but carries multiple root schemas that share a
|
|
81
|
+
* single definitions pool. The `schemas` tuple is non-empty (at least one
|
|
82
|
+
* element).
|
|
83
|
+
*
|
|
84
|
+
* - Use when generating several schemas (e.g. request body + response body)
|
|
85
|
+
* that reference the same set of definitions.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link Document}
|
|
88
|
+
* @see {@link toMultiDocumentOpenApi3_1}
|
|
89
|
+
*
|
|
36
90
|
* @since 4.0.0
|
|
37
91
|
*/
|
|
38
92
|
export interface MultiDocument<D extends Dialect> {
|
|
@@ -41,46 +95,281 @@ export interface MultiDocument<D extends Dialect> {
|
|
|
41
95
|
readonly definitions: Definitions;
|
|
42
96
|
}
|
|
43
97
|
/**
|
|
98
|
+
* The `$schema` meta-schema URI for JSON Schema Draft-07.
|
|
99
|
+
*
|
|
44
100
|
* @since 4.0.0
|
|
45
101
|
*/
|
|
46
102
|
export declare const META_SCHEMA_URI_DRAFT_07 = "http://json-schema.org/draft-07/schema";
|
|
47
103
|
/**
|
|
104
|
+
* The `$schema` meta-schema URI for JSON Schema Draft 2020-12.
|
|
105
|
+
*
|
|
48
106
|
* @since 4.0.0
|
|
49
107
|
*/
|
|
50
108
|
export declare const META_SCHEMA_URI_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
51
109
|
/**
|
|
110
|
+
* Parses a raw Draft-07 JSON Schema into a `Document<"draft-2020-12">`.
|
|
111
|
+
*
|
|
112
|
+
* - Use when you have a JSON Schema that follows Draft-07 conventions.
|
|
113
|
+
* - Converts Draft-07 tuple syntax (`items` as array + `additionalItems`)
|
|
114
|
+
* to Draft-2020-12 form (`prefixItems` + `items`).
|
|
115
|
+
* - Rewrites `#/definitions/...` refs to `#/$defs/...`.
|
|
116
|
+
* - Extracts root-level `definitions` into the `definitions` field.
|
|
117
|
+
* - Does not mutate the input. Allocates a new `Document`.
|
|
118
|
+
* - Unsupported keywords (e.g. `if`/`then`/`else`, `$id`) are dropped.
|
|
119
|
+
*
|
|
120
|
+
* **Example** (Parsing a Draft-07 schema)
|
|
121
|
+
*
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { JsonSchema } from "effect"
|
|
124
|
+
*
|
|
125
|
+
* const raw: JsonSchema.JsonSchema = {
|
|
126
|
+
* type: "object",
|
|
127
|
+
* properties: {
|
|
128
|
+
* tags: {
|
|
129
|
+
* type: "array",
|
|
130
|
+
* items: { type: "string" }
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* const doc = JsonSchema.fromSchemaDraft07(raw)
|
|
136
|
+
* console.log(doc.dialect) // "draft-2020-12"
|
|
137
|
+
* console.log(doc.schema.properties) // { tags: { type: "array", items: { type: "string" } } }
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @see {@link fromSchemaDraft2020_12}
|
|
141
|
+
* @see {@link fromSchemaOpenApi3_0}
|
|
142
|
+
* @see {@link toDocumentDraft07}
|
|
143
|
+
*
|
|
52
144
|
* @since 4.0.0
|
|
53
145
|
*/
|
|
54
146
|
export declare function fromSchemaDraft07(js: JsonSchema): Document<"draft-2020-12">;
|
|
55
147
|
/**
|
|
148
|
+
* Parses a raw Draft-2020-12 JSON Schema into a `Document<"draft-2020-12">`.
|
|
149
|
+
*
|
|
150
|
+
* - Use when you already have a schema in Draft-2020-12 format.
|
|
151
|
+
* - Separates `$defs` from the root schema into the `definitions` field.
|
|
152
|
+
* - Does not mutate the input. Allocates a new `Document`.
|
|
153
|
+
* - Unlike {@link fromSchemaDraft07}, this performs no keyword rewriting.
|
|
154
|
+
*
|
|
155
|
+
* **Example** (Parsing a Draft-2020-12 schema)
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { JsonSchema } from "effect"
|
|
159
|
+
*
|
|
160
|
+
* const raw: JsonSchema.JsonSchema = {
|
|
161
|
+
* type: "number",
|
|
162
|
+
* minimum: 0,
|
|
163
|
+
* $defs: { PositiveInt: { type: "integer", minimum: 1 } }
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* const doc = JsonSchema.fromSchemaDraft2020_12(raw)
|
|
167
|
+
* console.log(doc.schema) // { type: "number", minimum: 0 }
|
|
168
|
+
* console.log(doc.definitions) // { PositiveInt: { type: "integer", minimum: 1 } }
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @see {@link fromSchemaDraft07}
|
|
172
|
+
* @see {@link fromSchemaOpenApi3_1}
|
|
173
|
+
*
|
|
56
174
|
* @since 4.0.0
|
|
57
175
|
*/
|
|
58
176
|
export declare function fromSchemaDraft2020_12(js: JsonSchema): Document<"draft-2020-12">;
|
|
59
177
|
/**
|
|
178
|
+
* Parses a raw OpenAPI 3.1 JSON Schema into a `Document<"draft-2020-12">`.
|
|
179
|
+
*
|
|
180
|
+
* - Use when consuming schemas from an OpenAPI 3.1 specification.
|
|
181
|
+
* - Rewrites `#/components/schemas/...` refs to `#/$defs/...`.
|
|
182
|
+
* - Delegates to {@link fromSchemaDraft2020_12} after rewriting refs.
|
|
183
|
+
* - Does not mutate the input. Allocates a new `Document`.
|
|
184
|
+
*
|
|
185
|
+
* **Example** (Parsing an OpenAPI 3.1 schema)
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* import { JsonSchema } from "effect"
|
|
189
|
+
*
|
|
190
|
+
* const raw: JsonSchema.JsonSchema = {
|
|
191
|
+
* type: "object",
|
|
192
|
+
* properties: {
|
|
193
|
+
* user: { $ref: "#/components/schemas/User" }
|
|
194
|
+
* }
|
|
195
|
+
* }
|
|
196
|
+
*
|
|
197
|
+
* const doc = JsonSchema.fromSchemaOpenApi3_1(raw)
|
|
198
|
+
* // $ref is rewritten to Draft-2020-12 form
|
|
199
|
+
* console.log(doc.schema.properties) // { user: { $ref: "#/$defs/User" } }
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @see {@link fromSchemaOpenApi3_0}
|
|
203
|
+
* @see {@link toMultiDocumentOpenApi3_1}
|
|
204
|
+
*
|
|
60
205
|
* @since 4.0.0
|
|
61
206
|
*/
|
|
62
207
|
export declare function fromSchemaOpenApi3_1(js: JsonSchema): Document<"draft-2020-12">;
|
|
63
208
|
/**
|
|
209
|
+
* Parses a raw OpenAPI 3.0 JSON Schema into a `Document<"draft-2020-12">`.
|
|
210
|
+
*
|
|
211
|
+
* - Use when consuming schemas from an OpenAPI 3.0 specification.
|
|
212
|
+
* - Handles OpenAPI 3.0 extensions: `nullable`, singular `example`,
|
|
213
|
+
* boolean `exclusiveMinimum`/`exclusiveMaximum`.
|
|
214
|
+
* - Normalizes the schema to Draft-07 first, then converts to
|
|
215
|
+
* Draft-2020-12 via {@link fromSchemaDraft07}.
|
|
216
|
+
* - Does not mutate the input. Allocates a new `Document`.
|
|
217
|
+
*
|
|
218
|
+
* **Example** (Parsing an OpenAPI 3.0 nullable schema)
|
|
219
|
+
*
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { JsonSchema } from "effect"
|
|
222
|
+
*
|
|
223
|
+
* const raw: JsonSchema.JsonSchema = {
|
|
224
|
+
* type: "string",
|
|
225
|
+
* nullable: true
|
|
226
|
+
* }
|
|
227
|
+
*
|
|
228
|
+
* const doc = JsonSchema.fromSchemaOpenApi3_0(raw)
|
|
229
|
+
* // nullable is expanded into a type array
|
|
230
|
+
* console.log(doc.schema.type) // ["string", "null"]
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @see {@link fromSchemaOpenApi3_1}
|
|
234
|
+
* @see {@link fromSchemaDraft07}
|
|
235
|
+
*
|
|
64
236
|
* @since 4.0.0
|
|
65
237
|
*/
|
|
66
238
|
export declare function fromSchemaOpenApi3_0(schema: JsonSchema): Document<"draft-2020-12">;
|
|
67
239
|
/**
|
|
240
|
+
* Converts a `Document<"draft-2020-12">` to a `Document<"draft-07">`.
|
|
241
|
+
*
|
|
242
|
+
* - Use when you need to output a schema in Draft-07 format.
|
|
243
|
+
* - Rewrites `#/$defs/...` refs to `#/definitions/...`.
|
|
244
|
+
* - Converts Draft-2020-12 tuple syntax (`prefixItems` + `items`) to
|
|
245
|
+
* Draft-07 form (`items` as array + `additionalItems`).
|
|
246
|
+
* - Converts both the root schema and all definitions.
|
|
247
|
+
* - Does not mutate the input. Allocates a new `Document`.
|
|
248
|
+
* - Unsupported Draft-2020-12 keywords are dropped.
|
|
249
|
+
*
|
|
250
|
+
* **Example** (Converting to Draft-07)
|
|
251
|
+
*
|
|
252
|
+
* ```ts
|
|
253
|
+
* import { JsonSchema } from "effect"
|
|
254
|
+
*
|
|
255
|
+
* const doc = JsonSchema.fromSchemaDraft2020_12({
|
|
256
|
+
* type: "array",
|
|
257
|
+
* prefixItems: [{ type: "string" }, { type: "number" }],
|
|
258
|
+
* items: { type: "boolean" }
|
|
259
|
+
* })
|
|
260
|
+
*
|
|
261
|
+
* const draft07 = JsonSchema.toDocumentDraft07(doc)
|
|
262
|
+
* console.log(draft07.dialect) // "draft-07"
|
|
263
|
+
* console.log(draft07.schema.items) // [{ type: "string" }, { type: "number" }]
|
|
264
|
+
* console.log(draft07.schema.additionalItems) // { type: "boolean" }
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @see {@link fromSchemaDraft07}
|
|
268
|
+
* @see {@link toMultiDocumentOpenApi3_1}
|
|
269
|
+
*
|
|
68
270
|
* @since 4.0.0
|
|
69
271
|
*/
|
|
70
272
|
export declare function toDocumentDraft07(document: Document<"draft-2020-12">): Document<"draft-07">;
|
|
71
273
|
/**
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
274
|
+
* Converts a `MultiDocument<"draft-2020-12">` to a
|
|
275
|
+
* `MultiDocument<"openapi-3.1">`.
|
|
276
|
+
*
|
|
277
|
+
* - Use when generating an OpenAPI 3.1 specification from internal schemas.
|
|
278
|
+
* - Rewrites `#/$defs/...` refs to `#/components/schemas/...`.
|
|
279
|
+
* - Sanitizes definition keys to match the OpenAPI component key pattern
|
|
280
|
+
* (`^[a-zA-Z0-9.\-_]+$`), replacing invalid characters with `_`.
|
|
281
|
+
* - Updates all `$ref` pointers to use the sanitized keys.
|
|
282
|
+
* - Converts all schemas and definitions in the multi-document.
|
|
283
|
+
* - Does not mutate the input. Allocates a new `MultiDocument`.
|
|
284
|
+
*
|
|
285
|
+
* **Example** (Converting to OpenAPI 3.1)
|
|
286
|
+
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* import { JsonSchema } from "effect"
|
|
289
|
+
*
|
|
290
|
+
* const multi: JsonSchema.MultiDocument<"draft-2020-12"> = {
|
|
291
|
+
* dialect: "draft-2020-12",
|
|
292
|
+
* schemas: [{ $ref: "#/$defs/User" }],
|
|
293
|
+
* definitions: {
|
|
294
|
+
* User: { type: "object", properties: { name: { type: "string" } } }
|
|
295
|
+
* }
|
|
296
|
+
* }
|
|
297
|
+
*
|
|
298
|
+
* const openapi = JsonSchema.toMultiDocumentOpenApi3_1(multi)
|
|
299
|
+
* console.log(openapi.dialect) // "openapi-3.1"
|
|
300
|
+
* console.log(openapi.schemas[0]) // { $ref: "#/components/schemas/User" }
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @see {@link toDocumentDraft07}
|
|
304
|
+
* @see {@link MultiDocument}
|
|
305
|
+
*
|
|
76
306
|
* @since 4.0.0
|
|
77
307
|
*/
|
|
78
308
|
export declare function toMultiDocumentOpenApi3_1(multiDocument: MultiDocument<"draft-2020-12">): MultiDocument<"openapi-3.1">;
|
|
79
309
|
/**
|
|
310
|
+
* Resolves a `$ref` string by looking up the last path segment in a
|
|
311
|
+
* definitions map.
|
|
312
|
+
*
|
|
313
|
+
* - Use when you need to dereference a `$ref` pointer to get the
|
|
314
|
+
* actual schema it points to.
|
|
315
|
+
* - Only resolves the final segment of the ref path (e.g. `"User"` from
|
|
316
|
+
* `"#/$defs/User"`); does not follow arbitrary JSON Pointer paths.
|
|
317
|
+
* - Returns `undefined` if the definition is not found.
|
|
318
|
+
* - Does not mutate anything. Pure function.
|
|
319
|
+
*
|
|
320
|
+
* **Example** (Resolving a $ref)
|
|
321
|
+
*
|
|
322
|
+
* ```ts
|
|
323
|
+
* import { JsonSchema } from "effect"
|
|
324
|
+
*
|
|
325
|
+
* const definitions: JsonSchema.Definitions = {
|
|
326
|
+
* User: { type: "object", properties: { name: { type: "string" } } }
|
|
327
|
+
* }
|
|
328
|
+
*
|
|
329
|
+
* const result = JsonSchema.resolve$ref("#/$defs/User", definitions)
|
|
330
|
+
* console.log(result) // { type: "object", properties: { name: { type: "string" } } }
|
|
331
|
+
*
|
|
332
|
+
* const missing = JsonSchema.resolve$ref("#/$defs/Unknown", definitions)
|
|
333
|
+
* console.log(missing) // undefined
|
|
334
|
+
* ```
|
|
335
|
+
*
|
|
336
|
+
* @see {@link resolveTopLevel$ref}
|
|
337
|
+
* @see {@link Definitions}
|
|
338
|
+
*
|
|
80
339
|
* @since 4.0.0
|
|
81
340
|
*/
|
|
82
341
|
export declare function resolve$ref($ref: string, definitions: Definitions): JsonSchema | undefined;
|
|
83
342
|
/**
|
|
343
|
+
* If the root schema of a document is a `$ref`, resolves it against the
|
|
344
|
+
* document's definitions and returns a new document with the inlined
|
|
345
|
+
* schema. Returns the original document unchanged if the root schema is
|
|
346
|
+
* not a `$ref` or if the referenced definition is not found.
|
|
347
|
+
*
|
|
348
|
+
* - Use to dereference a top-level `$ref` before inspecting the root
|
|
349
|
+
* schema's properties directly.
|
|
350
|
+
* - Does not mutate the input. Returns the same object if no change is
|
|
351
|
+
* needed, or a shallow copy with the resolved schema.
|
|
352
|
+
*
|
|
353
|
+
* **Example** (Resolving a top-level $ref)
|
|
354
|
+
*
|
|
355
|
+
* ```ts
|
|
356
|
+
* import { JsonSchema } from "effect"
|
|
357
|
+
*
|
|
358
|
+
* const doc: JsonSchema.Document<"draft-2020-12"> = {
|
|
359
|
+
* dialect: "draft-2020-12",
|
|
360
|
+
* schema: { $ref: "#/$defs/User" },
|
|
361
|
+
* definitions: {
|
|
362
|
+
* User: { type: "object", properties: { name: { type: "string" } } }
|
|
363
|
+
* }
|
|
364
|
+
* }
|
|
365
|
+
*
|
|
366
|
+
* const resolved = JsonSchema.resolveTopLevel$ref(doc)
|
|
367
|
+
* console.log(resolved.schema) // { type: "object", properties: { name: { type: "string" } } }
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @see {@link resolve$ref}
|
|
371
|
+
* @see {@link Document}
|
|
372
|
+
*
|
|
84
373
|
* @since 4.0.0
|
|
85
374
|
*/
|
|
86
375
|
export declare function resolveTopLevel$ref(document: Document<"draft-2020-12">): Document<"draft-2020-12">;
|
package/dist/JsonSchema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSchema.d.ts","sourceRoot":"","sources":["../src/JsonSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JsonSchema.d.ts","sourceRoot":"","sources":["../src/JsonSchema.ts"],"names":[],"mappings":"AA2FA;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CACrB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,eAAe,GAAG,aAAa,GAAG,aAAa,CAAA;AAElF;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;AAE5F;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;CAAG;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,OAAO;IACzC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,OAAO;IAC9C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;IAC7D,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;CAClC;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,2CAA2C,CAAA;AAEhF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,iDAAiD,CAAA;AAM3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,CA0G3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,CAOhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,CAG9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,CAGlF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAM3F;AAuGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,aAAa,CAAC,aAAa,CAAC,CA+BrH;AA0JD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS,CAS1F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,CAQlG"}
|