effect 3.9.2 → 3.10.1
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/Arbitrary/package.json +6 -0
- package/FastCheck/package.json +6 -0
- package/JSONSchema/package.json +6 -0
- package/ParseResult/package.json +6 -0
- package/Pretty/package.json +6 -0
- package/Schema/package.json +6 -0
- package/SchemaAST/package.json +6 -0
- package/TSubscriptionRef/package.json +6 -0
- package/dist/cjs/Arbitrary.js +490 -0
- package/dist/cjs/Arbitrary.js.map +1 -0
- package/dist/cjs/Effect.js +247 -16
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/FastCheck.js +17 -0
- package/dist/cjs/FastCheck.js.map +1 -0
- package/dist/cjs/Inspectable.js +43 -3
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/JSONSchema.js +418 -0
- package/dist/cjs/JSONSchema.js.map +1 -0
- package/dist/cjs/ParseResult.js +1539 -0
- package/dist/cjs/ParseResult.js.map +1 -0
- package/dist/cjs/Predicate.js +3 -1
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Pretty.js +183 -0
- package/dist/cjs/Pretty.js.map +1 -0
- package/dist/cjs/Schema.js +5529 -0
- package/dist/cjs/Schema.js.map +1 -0
- package/dist/cjs/SchemaAST.js +2365 -0
- package/dist/cjs/SchemaAST.js.map +1 -0
- package/dist/cjs/Stream.js +17 -3
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/TPubSub.js +9 -1
- package/dist/cjs/TPubSub.js.map +1 -1
- package/dist/cjs/TQueue.js.map +1 -1
- package/dist/cjs/TRef.js.map +1 -1
- package/dist/cjs/TSubscriptionRef.js +96 -0
- package/dist/cjs/TSubscriptionRef.js.map +1 -0
- package/dist/cjs/index.js +18 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +2 -2
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js +160 -161
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/core.js +4 -4
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +14 -12
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +7 -6
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/redacted.js +4 -0
- package/dist/cjs/internal/redacted.js.map +1 -1
- package/dist/cjs/internal/schema/errors.js +116 -0
- package/dist/cjs/internal/schema/errors.js.map +1 -0
- package/dist/cjs/internal/schema/filters.js +41 -0
- package/dist/cjs/internal/schema/filters.js.map +1 -0
- package/dist/cjs/internal/schema/util.js +96 -0
- package/dist/cjs/internal/schema/util.js.map +1 -0
- package/dist/cjs/internal/stm/core.js +2 -3
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/stm/tPubSub.js.map +1 -1
- package/dist/cjs/internal/stm/tQueue.js +1 -2
- package/dist/cjs/internal/stm/tQueue.js.map +1 -1
- package/dist/cjs/internal/stm/tRef.js +6 -2
- package/dist/cjs/internal/stm/tRef.js.map +1 -1
- package/dist/cjs/internal/stm/tSubscriptionRef.js +178 -0
- package/dist/cjs/internal/stm/tSubscriptionRef.js.map +1 -0
- package/dist/cjs/internal/stream.js +36 -16
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Arbitrary.d.ts +45 -0
- package/dist/dts/Arbitrary.d.ts.map +1 -0
- package/dist/dts/Effect.d.ts +298 -30
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/FastCheck.d.ts +9 -0
- package/dist/dts/FastCheck.d.ts.map +1 -0
- package/dist/dts/Inspectable.d.ts +28 -0
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts +181 -0
- package/dist/dts/JSONSchema.d.ts.map +1 -0
- package/dist/dts/ParseResult.d.ts +551 -0
- package/dist/dts/ParseResult.d.ts.map +1 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Pretty.d.ts +26 -0
- package/dist/dts/Pretty.d.ts.map +1 -0
- package/dist/dts/Schema.d.ts +4562 -0
- package/dist/dts/Schema.d.ts.map +1 -0
- package/dist/dts/SchemaAST.d.ts +1321 -0
- package/dist/dts/SchemaAST.d.ts.map +1 -0
- package/dist/dts/Stream.d.ts +67 -2
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/TPubSub.d.ts +8 -0
- package/dist/dts/TPubSub.d.ts.map +1 -1
- package/dist/dts/TQueue.d.ts +7 -7
- package/dist/dts/TQueue.d.ts.map +1 -1
- package/dist/dts/TRef.d.ts +2 -1
- package/dist/dts/TRef.d.ts.map +1 -1
- package/dist/dts/TSubscriptionRef.d.ts +251 -0
- package/dist/dts/TSubscriptionRef.d.ts.map +1 -0
- package/dist/dts/index.d.ts +32 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/schema/errors.d.ts +2 -0
- package/dist/dts/internal/schema/errors.d.ts.map +1 -0
- package/dist/dts/internal/schema/filters.d.ts +2 -0
- package/dist/dts/internal/schema/filters.d.ts.map +1 -0
- package/dist/dts/internal/schema/util.d.ts +2 -0
- package/dist/dts/internal/schema/util.d.ts.map +1 -0
- package/dist/dts/internal/stm/tRef.d.ts +3 -1
- package/dist/dts/internal/stm/tRef.d.ts.map +1 -1
- package/dist/dts/internal/stm/tSubscriptionRef.d.ts +2 -0
- package/dist/dts/internal/stm/tSubscriptionRef.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Arbitrary.js +472 -0
- package/dist/esm/Arbitrary.js.map +1 -0
- package/dist/esm/Effect.js +256 -18
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/FastCheck.js +9 -0
- package/dist/esm/FastCheck.js.map +1 -0
- package/dist/esm/Inspectable.js +39 -2
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/JSONSchema.js +408 -0
- package/dist/esm/JSONSchema.js.map +1 -0
- package/dist/esm/ParseResult.js +1503 -0
- package/dist/esm/ParseResult.js.map +1 -0
- package/dist/esm/Predicate.js +2 -1
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Pretty.js +173 -0
- package/dist/esm/Pretty.js.map +1 -0
- package/dist/esm/Schema.js +5328 -0
- package/dist/esm/Schema.js.map +1 -0
- package/dist/esm/SchemaAST.js +2300 -0
- package/dist/esm/SchemaAST.js.map +1 -0
- package/dist/esm/Stream.js +14 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/TPubSub.js +8 -0
- package/dist/esm/TPubSub.js.map +1 -1
- package/dist/esm/TQueue.js.map +1 -1
- package/dist/esm/TRef.js.map +1 -1
- package/dist/esm/TSubscriptionRef.js +87 -0
- package/dist/esm/TSubscriptionRef.js.map +1 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +3 -3
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js +160 -161
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/core.js +4 -4
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +14 -12
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +7 -6
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/redacted.js +4 -0
- package/dist/esm/internal/redacted.js.map +1 -1
- package/dist/esm/internal/schema/errors.js +87 -0
- package/dist/esm/internal/schema/errors.js.map +1 -0
- package/dist/esm/internal/schema/filters.js +35 -0
- package/dist/esm/internal/schema/filters.js.map +1 -0
- package/dist/esm/internal/schema/util.js +78 -0
- package/dist/esm/internal/schema/util.js.map +1 -0
- package/dist/esm/internal/stm/core.js +1 -2
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/stm/tPubSub.js.map +1 -1
- package/dist/esm/internal/stm/tQueue.js +1 -2
- package/dist/esm/internal/stm/tQueue.js.map +1 -1
- package/dist/esm/internal/stm/tRef.js +5 -1
- package/dist/esm/internal/stm/tRef.js.map +1 -1
- package/dist/esm/internal/stm/tSubscriptionRef.js +166 -0
- package/dist/esm/internal/stm/tSubscriptionRef.js.map +1 -0
- package/dist/esm/internal/stream.js +33 -15
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +68 -1
- package/src/Arbitrary.ts +563 -0
- package/src/Effect.ts +302 -31
- package/src/FastCheck.ts +9 -0
- package/src/Inspectable.ts +56 -2
- package/src/JSONSchema.ts +601 -0
- package/src/ParseResult.ts +2027 -0
- package/src/Predicate.ts +3 -1
- package/src/Pretty.ts +204 -0
- package/src/Schema.ts +10388 -0
- package/src/SchemaAST.ts +2827 -0
- package/src/Stream.ts +77 -9
- package/src/TPubSub.ts +9 -0
- package/src/TQueue.ts +7 -7
- package/src/TRef.ts +2 -1
- package/src/TSubscriptionRef.ts +284 -0
- package/src/index.ts +40 -0
- package/src/internal/cause.ts +3 -3
- package/src/internal/channel/channelExecutor.ts +213 -214
- package/src/internal/core-effect.ts +2 -2
- package/src/internal/core.ts +4 -4
- package/src/internal/fiberRuntime.ts +14 -12
- package/src/internal/logger.ts +7 -6
- package/src/internal/redacted.ts +4 -0
- package/src/internal/schema/errors.ts +189 -0
- package/src/internal/schema/filters.ts +86 -0
- package/src/internal/schema/util.ts +113 -0
- package/src/internal/stm/core.ts +1 -2
- package/src/internal/stm/tPubSub.ts +1 -0
- package/src/internal/stm/tQueue.ts +2 -2
- package/src/internal/stm/tRef.ts +7 -2
- package/src/internal/stm/tSubscriptionRef.ts +286 -0
- package/src/internal/stream.ts +97 -20
- package/src/internal/version.ts +1 -1
|
@@ -0,0 +1,2300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 3.10.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Arr from "./Array.js";
|
|
5
|
+
import { dual, identity } from "./Function.js";
|
|
6
|
+
import { globalValue } from "./GlobalValue.js";
|
|
7
|
+
import * as errors_ from "./internal/schema/errors.js";
|
|
8
|
+
import * as util_ from "./internal/schema/util.js";
|
|
9
|
+
import * as Number from "./Number.js";
|
|
10
|
+
import * as Option from "./Option.js";
|
|
11
|
+
import * as Order from "./Order.js";
|
|
12
|
+
import * as Predicate from "./Predicate.js";
|
|
13
|
+
import * as regexp from "./RegExp.js";
|
|
14
|
+
/**
|
|
15
|
+
* @category annotations
|
|
16
|
+
* @since 3.10.0
|
|
17
|
+
*/
|
|
18
|
+
export const BrandAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Brand");
|
|
19
|
+
/**
|
|
20
|
+
* @category annotations
|
|
21
|
+
* @since 3.10.0
|
|
22
|
+
*/
|
|
23
|
+
export const SchemaIdAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/SchemaId");
|
|
24
|
+
/**
|
|
25
|
+
* @category annotations
|
|
26
|
+
* @since 3.10.0
|
|
27
|
+
*/
|
|
28
|
+
export const MessageAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Message");
|
|
29
|
+
/**
|
|
30
|
+
* @category annotations
|
|
31
|
+
* @since 3.10.0
|
|
32
|
+
*/
|
|
33
|
+
export const MissingMessageAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/MissingMessage");
|
|
34
|
+
/**
|
|
35
|
+
* @category annotations
|
|
36
|
+
* @since 3.10.0
|
|
37
|
+
*/
|
|
38
|
+
export const IdentifierAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Identifier");
|
|
39
|
+
/**
|
|
40
|
+
* @category annotations
|
|
41
|
+
* @since 3.10.0
|
|
42
|
+
*/
|
|
43
|
+
export const TitleAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Title");
|
|
44
|
+
/**
|
|
45
|
+
* @category annotations
|
|
46
|
+
* @since 3.10.0
|
|
47
|
+
*/
|
|
48
|
+
export const DescriptionAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Description");
|
|
49
|
+
/**
|
|
50
|
+
* @category annotations
|
|
51
|
+
* @since 3.10.0
|
|
52
|
+
*/
|
|
53
|
+
export const ExamplesAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Examples");
|
|
54
|
+
/**
|
|
55
|
+
* @category annotations
|
|
56
|
+
* @since 3.10.0
|
|
57
|
+
*/
|
|
58
|
+
export const DefaultAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Default");
|
|
59
|
+
/**
|
|
60
|
+
* @category annotations
|
|
61
|
+
* @since 3.10.0
|
|
62
|
+
*/
|
|
63
|
+
export const JSONSchemaAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/JSONSchema");
|
|
64
|
+
/**
|
|
65
|
+
* @category annotations
|
|
66
|
+
* @since 3.10.0
|
|
67
|
+
*/
|
|
68
|
+
export const ArbitraryAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Arbitrary");
|
|
69
|
+
/**
|
|
70
|
+
* @category annotations
|
|
71
|
+
* @since 3.10.0
|
|
72
|
+
*/
|
|
73
|
+
export const PrettyAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Pretty");
|
|
74
|
+
/**
|
|
75
|
+
* @category annotations
|
|
76
|
+
* @since 3.10.0
|
|
77
|
+
*/
|
|
78
|
+
export const EquivalenceAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Equivalence");
|
|
79
|
+
/**
|
|
80
|
+
* @category annotations
|
|
81
|
+
* @since 3.10.0
|
|
82
|
+
*/
|
|
83
|
+
export const DocumentationAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Documentation");
|
|
84
|
+
/**
|
|
85
|
+
* @category annotations
|
|
86
|
+
* @since 3.10.0
|
|
87
|
+
*/
|
|
88
|
+
export const ConcurrencyAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Concurrency");
|
|
89
|
+
/**
|
|
90
|
+
* @category annotations
|
|
91
|
+
* @since 3.10.0
|
|
92
|
+
*/
|
|
93
|
+
export const BatchingAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Batching");
|
|
94
|
+
/**
|
|
95
|
+
* @category annotations
|
|
96
|
+
* @since 3.10.0
|
|
97
|
+
*/
|
|
98
|
+
export const ParseIssueTitleAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/ParseIssueTitle");
|
|
99
|
+
/**
|
|
100
|
+
* @category annotations
|
|
101
|
+
* @since 3.10.0
|
|
102
|
+
*/
|
|
103
|
+
export const ParseOptionsAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/ParseOptions");
|
|
104
|
+
/**
|
|
105
|
+
* @category annotations
|
|
106
|
+
* @since 3.10.0
|
|
107
|
+
*/
|
|
108
|
+
export const DecodingFallbackAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/DecodingFallback");
|
|
109
|
+
/**
|
|
110
|
+
* @category annotations
|
|
111
|
+
* @since 3.10.0
|
|
112
|
+
*/
|
|
113
|
+
export const SurrogateAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Surrogate");
|
|
114
|
+
/** @internal */
|
|
115
|
+
export const StableFilterAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/StableFilter");
|
|
116
|
+
/**
|
|
117
|
+
* @category annotations
|
|
118
|
+
* @since 3.10.0
|
|
119
|
+
*/
|
|
120
|
+
export const getAnnotation = /*#__PURE__*/dual(2, (annotated, key) => Object.prototype.hasOwnProperty.call(annotated.annotations, key) ? Option.some(annotated.annotations[key]) : Option.none());
|
|
121
|
+
/**
|
|
122
|
+
* @category annotations
|
|
123
|
+
* @since 3.10.0
|
|
124
|
+
*/
|
|
125
|
+
export const getBrandAnnotation = /*#__PURE__*/getAnnotation(BrandAnnotationId);
|
|
126
|
+
/**
|
|
127
|
+
* @category annotations
|
|
128
|
+
* @since 3.10.0
|
|
129
|
+
*/
|
|
130
|
+
export const getMessageAnnotation = /*#__PURE__*/getAnnotation(MessageAnnotationId);
|
|
131
|
+
/**
|
|
132
|
+
* @category annotations
|
|
133
|
+
* @since 3.10.0
|
|
134
|
+
*/
|
|
135
|
+
export const getMissingMessageAnnotation = /*#__PURE__*/getAnnotation(MissingMessageAnnotationId);
|
|
136
|
+
/**
|
|
137
|
+
* @category annotations
|
|
138
|
+
* @since 3.10.0
|
|
139
|
+
*/
|
|
140
|
+
export const getTitleAnnotation = /*#__PURE__*/getAnnotation(TitleAnnotationId);
|
|
141
|
+
/**
|
|
142
|
+
* @category annotations
|
|
143
|
+
* @since 3.10.0
|
|
144
|
+
*/
|
|
145
|
+
export const getIdentifierAnnotation = /*#__PURE__*/getAnnotation(IdentifierAnnotationId);
|
|
146
|
+
/**
|
|
147
|
+
* @category annotations
|
|
148
|
+
* @since 3.10.0
|
|
149
|
+
*/
|
|
150
|
+
export const getDescriptionAnnotation = /*#__PURE__*/getAnnotation(DescriptionAnnotationId);
|
|
151
|
+
/**
|
|
152
|
+
* @category annotations
|
|
153
|
+
* @since 3.10.0
|
|
154
|
+
*/
|
|
155
|
+
export const getExamplesAnnotation = /*#__PURE__*/getAnnotation(ExamplesAnnotationId);
|
|
156
|
+
/**
|
|
157
|
+
* @category annotations
|
|
158
|
+
* @since 3.10.0
|
|
159
|
+
*/
|
|
160
|
+
export const getDefaultAnnotation = /*#__PURE__*/getAnnotation(DefaultAnnotationId);
|
|
161
|
+
/**
|
|
162
|
+
* @category annotations
|
|
163
|
+
* @since 3.10.0
|
|
164
|
+
*/
|
|
165
|
+
export const getJSONSchemaAnnotation = /*#__PURE__*/getAnnotation(JSONSchemaAnnotationId);
|
|
166
|
+
/**
|
|
167
|
+
* @category annotations
|
|
168
|
+
* @since 3.10.0
|
|
169
|
+
*/
|
|
170
|
+
export const getDocumentationAnnotation = /*#__PURE__*/getAnnotation(DocumentationAnnotationId);
|
|
171
|
+
/**
|
|
172
|
+
* @category annotations
|
|
173
|
+
* @since 3.10.0
|
|
174
|
+
*/
|
|
175
|
+
export const getConcurrencyAnnotation = /*#__PURE__*/getAnnotation(ConcurrencyAnnotationId);
|
|
176
|
+
/**
|
|
177
|
+
* @category annotations
|
|
178
|
+
* @since 3.10.0
|
|
179
|
+
*/
|
|
180
|
+
export const getBatchingAnnotation = /*#__PURE__*/getAnnotation(BatchingAnnotationId);
|
|
181
|
+
/**
|
|
182
|
+
* @category annotations
|
|
183
|
+
* @since 3.10.0
|
|
184
|
+
*/
|
|
185
|
+
export const getParseIssueTitleAnnotation = /*#__PURE__*/getAnnotation(ParseIssueTitleAnnotationId);
|
|
186
|
+
/**
|
|
187
|
+
* @category annotations
|
|
188
|
+
* @since 3.10.0
|
|
189
|
+
*/
|
|
190
|
+
export const getParseOptionsAnnotation = /*#__PURE__*/getAnnotation(ParseOptionsAnnotationId);
|
|
191
|
+
/**
|
|
192
|
+
* @category annotations
|
|
193
|
+
* @since 3.10.0
|
|
194
|
+
*/
|
|
195
|
+
export const getDecodingFallbackAnnotation = /*#__PURE__*/getAnnotation(DecodingFallbackAnnotationId);
|
|
196
|
+
/**
|
|
197
|
+
* @category annotations
|
|
198
|
+
* @since 3.10.0
|
|
199
|
+
*/
|
|
200
|
+
export const getSurrogateAnnotation = /*#__PURE__*/getAnnotation(SurrogateAnnotationId);
|
|
201
|
+
const getStableFilterAnnotation = /*#__PURE__*/getAnnotation(StableFilterAnnotationId);
|
|
202
|
+
/** @internal */
|
|
203
|
+
export const hasStableFilter = annotated => Option.exists(getStableFilterAnnotation(annotated), b => b === true);
|
|
204
|
+
/**
|
|
205
|
+
* @category annotations
|
|
206
|
+
* @since 3.10.0
|
|
207
|
+
*/
|
|
208
|
+
export const JSONIdentifierAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/JSONIdentifier");
|
|
209
|
+
/**
|
|
210
|
+
* @category annotations
|
|
211
|
+
* @since 3.10.0
|
|
212
|
+
*/
|
|
213
|
+
export const getJSONIdentifierAnnotation = /*#__PURE__*/getAnnotation(JSONIdentifierAnnotationId);
|
|
214
|
+
/**
|
|
215
|
+
* @category annotations
|
|
216
|
+
* @since 3.10.0
|
|
217
|
+
*/
|
|
218
|
+
export const getJSONIdentifier = annotated => Option.orElse(getJSONIdentifierAnnotation(annotated), () => getIdentifierAnnotation(annotated));
|
|
219
|
+
// -------------------------------------------------------------------------------------
|
|
220
|
+
// schema ids
|
|
221
|
+
// -------------------------------------------------------------------------------------
|
|
222
|
+
/**
|
|
223
|
+
* @category schema id
|
|
224
|
+
* @since 3.10.0
|
|
225
|
+
*/
|
|
226
|
+
export const ParseJsonSchemaId = /*#__PURE__*/Symbol.for("effect/schema/ParseJson");
|
|
227
|
+
/**
|
|
228
|
+
* @category model
|
|
229
|
+
* @since 3.10.0
|
|
230
|
+
*/
|
|
231
|
+
export class Declaration {
|
|
232
|
+
typeParameters;
|
|
233
|
+
decodeUnknown;
|
|
234
|
+
encodeUnknown;
|
|
235
|
+
annotations;
|
|
236
|
+
/**
|
|
237
|
+
* @since 3.10.0
|
|
238
|
+
*/
|
|
239
|
+
_tag = "Declaration";
|
|
240
|
+
constructor(typeParameters, decodeUnknown, encodeUnknown, annotations = {}) {
|
|
241
|
+
this.typeParameters = typeParameters;
|
|
242
|
+
this.decodeUnknown = decodeUnknown;
|
|
243
|
+
this.encodeUnknown = encodeUnknown;
|
|
244
|
+
this.annotations = annotations;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* @since 3.10.0
|
|
248
|
+
*/
|
|
249
|
+
toString() {
|
|
250
|
+
return Option.getOrElse(getExpected(this), () => "<declaration schema>");
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* @since 3.10.0
|
|
254
|
+
*/
|
|
255
|
+
toJSON() {
|
|
256
|
+
return {
|
|
257
|
+
_tag: this._tag,
|
|
258
|
+
typeParameters: this.typeParameters.map(ast => ast.toJSON()),
|
|
259
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const createASTGuard = tag => ast => ast._tag === tag;
|
|
264
|
+
/**
|
|
265
|
+
* @category guards
|
|
266
|
+
* @since 3.10.0
|
|
267
|
+
*/
|
|
268
|
+
export const isDeclaration = /*#__PURE__*/createASTGuard("Declaration");
|
|
269
|
+
/**
|
|
270
|
+
* @category model
|
|
271
|
+
* @since 3.10.0
|
|
272
|
+
*/
|
|
273
|
+
export class Literal {
|
|
274
|
+
literal;
|
|
275
|
+
annotations;
|
|
276
|
+
/**
|
|
277
|
+
* @since 3.10.0
|
|
278
|
+
*/
|
|
279
|
+
_tag = "Literal";
|
|
280
|
+
constructor(literal, annotations = {}) {
|
|
281
|
+
this.literal = literal;
|
|
282
|
+
this.annotations = annotations;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* @since 3.10.0
|
|
286
|
+
*/
|
|
287
|
+
toString() {
|
|
288
|
+
return Option.getOrElse(getExpected(this), () => util_.formatUnknown(this.literal));
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @since 3.10.0
|
|
292
|
+
*/
|
|
293
|
+
toJSON() {
|
|
294
|
+
return {
|
|
295
|
+
_tag: this._tag,
|
|
296
|
+
literal: Predicate.isBigInt(this.literal) ? String(this.literal) : this.literal,
|
|
297
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* @category guards
|
|
303
|
+
* @since 3.10.0
|
|
304
|
+
*/
|
|
305
|
+
export const isLiteral = /*#__PURE__*/createASTGuard("Literal");
|
|
306
|
+
const $null = /*#__PURE__*/new Literal(null);
|
|
307
|
+
export {
|
|
308
|
+
/**
|
|
309
|
+
* @category constructors
|
|
310
|
+
* @since 3.10.0
|
|
311
|
+
*/
|
|
312
|
+
$null as null };
|
|
313
|
+
/**
|
|
314
|
+
* @category model
|
|
315
|
+
* @since 3.10.0
|
|
316
|
+
*/
|
|
317
|
+
export class UniqueSymbol {
|
|
318
|
+
symbol;
|
|
319
|
+
annotations;
|
|
320
|
+
/**
|
|
321
|
+
* @since 3.10.0
|
|
322
|
+
*/
|
|
323
|
+
_tag = "UniqueSymbol";
|
|
324
|
+
constructor(symbol, annotations = {}) {
|
|
325
|
+
this.symbol = symbol;
|
|
326
|
+
this.annotations = annotations;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* @since 3.10.0
|
|
330
|
+
*/
|
|
331
|
+
toString() {
|
|
332
|
+
return Option.getOrElse(getExpected(this), () => util_.formatUnknown(this.symbol));
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* @since 3.10.0
|
|
336
|
+
*/
|
|
337
|
+
toJSON() {
|
|
338
|
+
return {
|
|
339
|
+
_tag: this._tag,
|
|
340
|
+
symbol: String(this.symbol),
|
|
341
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* @category guards
|
|
347
|
+
* @since 3.10.0
|
|
348
|
+
*/
|
|
349
|
+
export const isUniqueSymbol = /*#__PURE__*/createASTGuard("UniqueSymbol");
|
|
350
|
+
/**
|
|
351
|
+
* @category model
|
|
352
|
+
* @since 3.10.0
|
|
353
|
+
*/
|
|
354
|
+
export class UndefinedKeyword {
|
|
355
|
+
annotations;
|
|
356
|
+
/**
|
|
357
|
+
* @since 3.10.0
|
|
358
|
+
*/
|
|
359
|
+
_tag = "UndefinedKeyword";
|
|
360
|
+
constructor(annotations = {}) {
|
|
361
|
+
this.annotations = annotations;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* @since 3.10.0
|
|
365
|
+
*/
|
|
366
|
+
toString() {
|
|
367
|
+
return formatKeyword(this);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* @since 3.10.0
|
|
371
|
+
*/
|
|
372
|
+
toJSON() {
|
|
373
|
+
return {
|
|
374
|
+
_tag: this._tag,
|
|
375
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* @category constructors
|
|
381
|
+
* @since 3.10.0
|
|
382
|
+
*/
|
|
383
|
+
export const undefinedKeyword = /*#__PURE__*/new UndefinedKeyword({
|
|
384
|
+
[TitleAnnotationId]: "undefined"
|
|
385
|
+
});
|
|
386
|
+
/**
|
|
387
|
+
* @category guards
|
|
388
|
+
* @since 3.10.0
|
|
389
|
+
*/
|
|
390
|
+
export const isUndefinedKeyword = /*#__PURE__*/createASTGuard("UndefinedKeyword");
|
|
391
|
+
/**
|
|
392
|
+
* @category model
|
|
393
|
+
* @since 3.10.0
|
|
394
|
+
*/
|
|
395
|
+
export class VoidKeyword {
|
|
396
|
+
annotations;
|
|
397
|
+
/**
|
|
398
|
+
* @since 3.10.0
|
|
399
|
+
*/
|
|
400
|
+
_tag = "VoidKeyword";
|
|
401
|
+
constructor(annotations = {}) {
|
|
402
|
+
this.annotations = annotations;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* @since 3.10.0
|
|
406
|
+
*/
|
|
407
|
+
toString() {
|
|
408
|
+
return formatKeyword(this);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* @since 3.10.0
|
|
412
|
+
*/
|
|
413
|
+
toJSON() {
|
|
414
|
+
return {
|
|
415
|
+
_tag: this._tag,
|
|
416
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* @category constructors
|
|
422
|
+
* @since 3.10.0
|
|
423
|
+
*/
|
|
424
|
+
export const voidKeyword = /*#__PURE__*/new VoidKeyword({
|
|
425
|
+
[TitleAnnotationId]: "void"
|
|
426
|
+
});
|
|
427
|
+
/**
|
|
428
|
+
* @category guards
|
|
429
|
+
* @since 3.10.0
|
|
430
|
+
*/
|
|
431
|
+
export const isVoidKeyword = /*#__PURE__*/createASTGuard("VoidKeyword");
|
|
432
|
+
/**
|
|
433
|
+
* @category model
|
|
434
|
+
* @since 3.10.0
|
|
435
|
+
*/
|
|
436
|
+
export class NeverKeyword {
|
|
437
|
+
annotations;
|
|
438
|
+
/**
|
|
439
|
+
* @since 3.10.0
|
|
440
|
+
*/
|
|
441
|
+
_tag = "NeverKeyword";
|
|
442
|
+
constructor(annotations = {}) {
|
|
443
|
+
this.annotations = annotations;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* @since 3.10.0
|
|
447
|
+
*/
|
|
448
|
+
toString() {
|
|
449
|
+
return formatKeyword(this);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* @since 3.10.0
|
|
453
|
+
*/
|
|
454
|
+
toJSON() {
|
|
455
|
+
return {
|
|
456
|
+
_tag: this._tag,
|
|
457
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* @category constructors
|
|
463
|
+
* @since 3.10.0
|
|
464
|
+
*/
|
|
465
|
+
export const neverKeyword = /*#__PURE__*/new NeverKeyword({
|
|
466
|
+
[TitleAnnotationId]: "never"
|
|
467
|
+
});
|
|
468
|
+
/**
|
|
469
|
+
* @category guards
|
|
470
|
+
* @since 3.10.0
|
|
471
|
+
*/
|
|
472
|
+
export const isNeverKeyword = /*#__PURE__*/createASTGuard("NeverKeyword");
|
|
473
|
+
/**
|
|
474
|
+
* @category model
|
|
475
|
+
* @since 3.10.0
|
|
476
|
+
*/
|
|
477
|
+
export class UnknownKeyword {
|
|
478
|
+
annotations;
|
|
479
|
+
/**
|
|
480
|
+
* @since 3.10.0
|
|
481
|
+
*/
|
|
482
|
+
_tag = "UnknownKeyword";
|
|
483
|
+
constructor(annotations = {}) {
|
|
484
|
+
this.annotations = annotations;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* @since 3.10.0
|
|
488
|
+
*/
|
|
489
|
+
toString() {
|
|
490
|
+
return formatKeyword(this);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* @since 3.10.0
|
|
494
|
+
*/
|
|
495
|
+
toJSON() {
|
|
496
|
+
return {
|
|
497
|
+
_tag: this._tag,
|
|
498
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* @category constructors
|
|
504
|
+
* @since 3.10.0
|
|
505
|
+
*/
|
|
506
|
+
export const unknownKeyword = /*#__PURE__*/new UnknownKeyword({
|
|
507
|
+
[TitleAnnotationId]: "unknown"
|
|
508
|
+
});
|
|
509
|
+
/**
|
|
510
|
+
* @category guards
|
|
511
|
+
* @since 3.10.0
|
|
512
|
+
*/
|
|
513
|
+
export const isUnknownKeyword = /*#__PURE__*/createASTGuard("UnknownKeyword");
|
|
514
|
+
/**
|
|
515
|
+
* @category model
|
|
516
|
+
* @since 3.10.0
|
|
517
|
+
*/
|
|
518
|
+
export class AnyKeyword {
|
|
519
|
+
annotations;
|
|
520
|
+
/**
|
|
521
|
+
* @since 3.10.0
|
|
522
|
+
*/
|
|
523
|
+
_tag = "AnyKeyword";
|
|
524
|
+
constructor(annotations = {}) {
|
|
525
|
+
this.annotations = annotations;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* @since 3.10.0
|
|
529
|
+
*/
|
|
530
|
+
toString() {
|
|
531
|
+
return formatKeyword(this);
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* @since 3.10.0
|
|
535
|
+
*/
|
|
536
|
+
toJSON() {
|
|
537
|
+
return {
|
|
538
|
+
_tag: this._tag,
|
|
539
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* @category constructors
|
|
545
|
+
* @since 3.10.0
|
|
546
|
+
*/
|
|
547
|
+
export const anyKeyword = /*#__PURE__*/new AnyKeyword({
|
|
548
|
+
[TitleAnnotationId]: "any"
|
|
549
|
+
});
|
|
550
|
+
/**
|
|
551
|
+
* @category guards
|
|
552
|
+
* @since 3.10.0
|
|
553
|
+
*/
|
|
554
|
+
export const isAnyKeyword = /*#__PURE__*/createASTGuard("AnyKeyword");
|
|
555
|
+
/**
|
|
556
|
+
* @category model
|
|
557
|
+
* @since 3.10.0
|
|
558
|
+
*/
|
|
559
|
+
export class StringKeyword {
|
|
560
|
+
annotations;
|
|
561
|
+
/**
|
|
562
|
+
* @since 3.10.0
|
|
563
|
+
*/
|
|
564
|
+
_tag = "StringKeyword";
|
|
565
|
+
constructor(annotations = {}) {
|
|
566
|
+
this.annotations = annotations;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* @since 3.10.0
|
|
570
|
+
*/
|
|
571
|
+
toString() {
|
|
572
|
+
return formatKeyword(this);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* @since 3.10.0
|
|
576
|
+
*/
|
|
577
|
+
toJSON() {
|
|
578
|
+
return {
|
|
579
|
+
_tag: this._tag,
|
|
580
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* @category constructors
|
|
586
|
+
* @since 3.10.0
|
|
587
|
+
*/
|
|
588
|
+
export const stringKeyword = /*#__PURE__*/new StringKeyword({
|
|
589
|
+
[TitleAnnotationId]: "string",
|
|
590
|
+
[DescriptionAnnotationId]: "a string"
|
|
591
|
+
});
|
|
592
|
+
/**
|
|
593
|
+
* @category guards
|
|
594
|
+
* @since 3.10.0
|
|
595
|
+
*/
|
|
596
|
+
export const isStringKeyword = /*#__PURE__*/createASTGuard("StringKeyword");
|
|
597
|
+
/**
|
|
598
|
+
* @category model
|
|
599
|
+
* @since 3.10.0
|
|
600
|
+
*/
|
|
601
|
+
export class NumberKeyword {
|
|
602
|
+
annotations;
|
|
603
|
+
/**
|
|
604
|
+
* @since 3.10.0
|
|
605
|
+
*/
|
|
606
|
+
_tag = "NumberKeyword";
|
|
607
|
+
constructor(annotations = {}) {
|
|
608
|
+
this.annotations = annotations;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* @since 3.10.0
|
|
612
|
+
*/
|
|
613
|
+
toString() {
|
|
614
|
+
return formatKeyword(this);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* @since 3.10.0
|
|
618
|
+
*/
|
|
619
|
+
toJSON() {
|
|
620
|
+
return {
|
|
621
|
+
_tag: this._tag,
|
|
622
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* @category constructors
|
|
628
|
+
* @since 3.10.0
|
|
629
|
+
*/
|
|
630
|
+
export const numberKeyword = /*#__PURE__*/new NumberKeyword({
|
|
631
|
+
[TitleAnnotationId]: "number",
|
|
632
|
+
[DescriptionAnnotationId]: "a number"
|
|
633
|
+
});
|
|
634
|
+
/**
|
|
635
|
+
* @category guards
|
|
636
|
+
* @since 3.10.0
|
|
637
|
+
*/
|
|
638
|
+
export const isNumberKeyword = /*#__PURE__*/createASTGuard("NumberKeyword");
|
|
639
|
+
/**
|
|
640
|
+
* @category model
|
|
641
|
+
* @since 3.10.0
|
|
642
|
+
*/
|
|
643
|
+
export class BooleanKeyword {
|
|
644
|
+
annotations;
|
|
645
|
+
/**
|
|
646
|
+
* @since 3.10.0
|
|
647
|
+
*/
|
|
648
|
+
_tag = "BooleanKeyword";
|
|
649
|
+
constructor(annotations = {}) {
|
|
650
|
+
this.annotations = annotations;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* @since 3.10.0
|
|
654
|
+
*/
|
|
655
|
+
toString() {
|
|
656
|
+
return formatKeyword(this);
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* @since 3.10.0
|
|
660
|
+
*/
|
|
661
|
+
toJSON() {
|
|
662
|
+
return {
|
|
663
|
+
_tag: this._tag,
|
|
664
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* @category constructors
|
|
670
|
+
* @since 3.10.0
|
|
671
|
+
*/
|
|
672
|
+
export const booleanKeyword = /*#__PURE__*/new BooleanKeyword({
|
|
673
|
+
[TitleAnnotationId]: "boolean",
|
|
674
|
+
[DescriptionAnnotationId]: "a boolean"
|
|
675
|
+
});
|
|
676
|
+
/**
|
|
677
|
+
* @category guards
|
|
678
|
+
* @since 3.10.0
|
|
679
|
+
*/
|
|
680
|
+
export const isBooleanKeyword = /*#__PURE__*/createASTGuard("BooleanKeyword");
|
|
681
|
+
/**
|
|
682
|
+
* @category model
|
|
683
|
+
* @since 3.10.0
|
|
684
|
+
*/
|
|
685
|
+
export class BigIntKeyword {
|
|
686
|
+
annotations;
|
|
687
|
+
/**
|
|
688
|
+
* @since 3.10.0
|
|
689
|
+
*/
|
|
690
|
+
_tag = "BigIntKeyword";
|
|
691
|
+
constructor(annotations = {}) {
|
|
692
|
+
this.annotations = annotations;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* @since 3.10.0
|
|
696
|
+
*/
|
|
697
|
+
toString() {
|
|
698
|
+
return formatKeyword(this);
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* @since 3.10.0
|
|
702
|
+
*/
|
|
703
|
+
toJSON() {
|
|
704
|
+
return {
|
|
705
|
+
_tag: this._tag,
|
|
706
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* @category constructors
|
|
712
|
+
* @since 3.10.0
|
|
713
|
+
*/
|
|
714
|
+
export const bigIntKeyword = /*#__PURE__*/new BigIntKeyword({
|
|
715
|
+
[TitleAnnotationId]: "bigint",
|
|
716
|
+
[DescriptionAnnotationId]: "a bigint"
|
|
717
|
+
});
|
|
718
|
+
/**
|
|
719
|
+
* @category guards
|
|
720
|
+
* @since 3.10.0
|
|
721
|
+
*/
|
|
722
|
+
export const isBigIntKeyword = /*#__PURE__*/createASTGuard("BigIntKeyword");
|
|
723
|
+
/**
|
|
724
|
+
* @category model
|
|
725
|
+
* @since 3.10.0
|
|
726
|
+
*/
|
|
727
|
+
export class SymbolKeyword {
|
|
728
|
+
annotations;
|
|
729
|
+
/**
|
|
730
|
+
* @since 3.10.0
|
|
731
|
+
*/
|
|
732
|
+
_tag = "SymbolKeyword";
|
|
733
|
+
constructor(annotations = {}) {
|
|
734
|
+
this.annotations = annotations;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* @since 3.10.0
|
|
738
|
+
*/
|
|
739
|
+
toString() {
|
|
740
|
+
return formatKeyword(this);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* @since 3.10.0
|
|
744
|
+
*/
|
|
745
|
+
toJSON() {
|
|
746
|
+
return {
|
|
747
|
+
_tag: this._tag,
|
|
748
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* @category constructors
|
|
754
|
+
* @since 3.10.0
|
|
755
|
+
*/
|
|
756
|
+
export const symbolKeyword = /*#__PURE__*/new SymbolKeyword({
|
|
757
|
+
[TitleAnnotationId]: "symbol",
|
|
758
|
+
[DescriptionAnnotationId]: "a symbol"
|
|
759
|
+
});
|
|
760
|
+
/**
|
|
761
|
+
* @category guards
|
|
762
|
+
* @since 3.10.0
|
|
763
|
+
*/
|
|
764
|
+
export const isSymbolKeyword = /*#__PURE__*/createASTGuard("SymbolKeyword");
|
|
765
|
+
/**
|
|
766
|
+
* @category model
|
|
767
|
+
* @since 3.10.0
|
|
768
|
+
*/
|
|
769
|
+
export class ObjectKeyword {
|
|
770
|
+
annotations;
|
|
771
|
+
/**
|
|
772
|
+
* @since 3.10.0
|
|
773
|
+
*/
|
|
774
|
+
_tag = "ObjectKeyword";
|
|
775
|
+
constructor(annotations = {}) {
|
|
776
|
+
this.annotations = annotations;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* @since 3.10.0
|
|
780
|
+
*/
|
|
781
|
+
toString() {
|
|
782
|
+
return formatKeyword(this);
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* @since 3.10.0
|
|
786
|
+
*/
|
|
787
|
+
toJSON() {
|
|
788
|
+
return {
|
|
789
|
+
_tag: this._tag,
|
|
790
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* @category constructors
|
|
796
|
+
* @since 3.10.0
|
|
797
|
+
*/
|
|
798
|
+
export const objectKeyword = /*#__PURE__*/new ObjectKeyword({
|
|
799
|
+
[TitleAnnotationId]: "object",
|
|
800
|
+
[DescriptionAnnotationId]: "an object in the TypeScript meaning, i.e. the `object` type"
|
|
801
|
+
});
|
|
802
|
+
/**
|
|
803
|
+
* @category guards
|
|
804
|
+
* @since 3.10.0
|
|
805
|
+
*/
|
|
806
|
+
export const isObjectKeyword = /*#__PURE__*/createASTGuard("ObjectKeyword");
|
|
807
|
+
/**
|
|
808
|
+
* @category model
|
|
809
|
+
* @since 3.10.0
|
|
810
|
+
*/
|
|
811
|
+
export class Enums {
|
|
812
|
+
enums;
|
|
813
|
+
annotations;
|
|
814
|
+
/**
|
|
815
|
+
* @since 3.10.0
|
|
816
|
+
*/
|
|
817
|
+
_tag = "Enums";
|
|
818
|
+
constructor(enums, annotations = {}) {
|
|
819
|
+
this.enums = enums;
|
|
820
|
+
this.annotations = annotations;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* @since 3.10.0
|
|
824
|
+
*/
|
|
825
|
+
toString() {
|
|
826
|
+
return Option.getOrElse(getExpected(this), () => `<enum ${this.enums.length} value(s): ${this.enums.map((_, value) => JSON.stringify(value)).join(" | ")}>`);
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* @since 3.10.0
|
|
830
|
+
*/
|
|
831
|
+
toJSON() {
|
|
832
|
+
return {
|
|
833
|
+
_tag: this._tag,
|
|
834
|
+
enums: this.enums,
|
|
835
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* @category guards
|
|
841
|
+
* @since 3.10.0
|
|
842
|
+
*/
|
|
843
|
+
export const isEnums = /*#__PURE__*/createASTGuard("Enums");
|
|
844
|
+
/**
|
|
845
|
+
* @category model
|
|
846
|
+
* @since 3.10.0
|
|
847
|
+
*/
|
|
848
|
+
export class TemplateLiteralSpan {
|
|
849
|
+
type;
|
|
850
|
+
literal;
|
|
851
|
+
constructor(type, literal) {
|
|
852
|
+
this.type = type;
|
|
853
|
+
this.literal = literal;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* @since 3.10.0
|
|
857
|
+
*/
|
|
858
|
+
toString() {
|
|
859
|
+
const type = "${" + String(this.type) + "}";
|
|
860
|
+
return type + this.literal;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* @since 3.10.0
|
|
864
|
+
*/
|
|
865
|
+
toJSON() {
|
|
866
|
+
return {
|
|
867
|
+
type: this.type.toJSON(),
|
|
868
|
+
literal: this.literal
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* @category model
|
|
874
|
+
* @since 3.10.0
|
|
875
|
+
*/
|
|
876
|
+
export class TemplateLiteral {
|
|
877
|
+
head;
|
|
878
|
+
spans;
|
|
879
|
+
annotations;
|
|
880
|
+
/**
|
|
881
|
+
* @since 3.10.0
|
|
882
|
+
*/
|
|
883
|
+
_tag = "TemplateLiteral";
|
|
884
|
+
constructor(head, spans, annotations = {}) {
|
|
885
|
+
this.head = head;
|
|
886
|
+
this.spans = spans;
|
|
887
|
+
this.annotations = annotations;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* @since 3.10.0
|
|
891
|
+
*/
|
|
892
|
+
toString() {
|
|
893
|
+
return Option.getOrElse(getExpected(this), () => formatTemplateLiteral(this));
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* @since 3.10.0
|
|
897
|
+
*/
|
|
898
|
+
toJSON() {
|
|
899
|
+
return {
|
|
900
|
+
_tag: this._tag,
|
|
901
|
+
head: this.head,
|
|
902
|
+
spans: this.spans.map(span => span.toJSON()),
|
|
903
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
const formatTemplateLiteral = ast => "`" + ast.head + ast.spans.map(span => String(span)).join("") + "`";
|
|
908
|
+
/**
|
|
909
|
+
* @category guards
|
|
910
|
+
* @since 3.10.0
|
|
911
|
+
*/
|
|
912
|
+
export const isTemplateLiteral = /*#__PURE__*/createASTGuard("TemplateLiteral");
|
|
913
|
+
/**
|
|
914
|
+
* @category model
|
|
915
|
+
* @since 3.10.0
|
|
916
|
+
*/
|
|
917
|
+
export class Type {
|
|
918
|
+
type;
|
|
919
|
+
annotations;
|
|
920
|
+
constructor(type, annotations = {}) {
|
|
921
|
+
this.type = type;
|
|
922
|
+
this.annotations = annotations;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* @since 3.10.0
|
|
926
|
+
*/
|
|
927
|
+
toJSON() {
|
|
928
|
+
return {
|
|
929
|
+
type: this.type.toJSON(),
|
|
930
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* @since 3.10.0
|
|
935
|
+
*/
|
|
936
|
+
toString() {
|
|
937
|
+
return String(this.type);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* @category model
|
|
942
|
+
* @since 3.10.0
|
|
943
|
+
*/
|
|
944
|
+
export class OptionalType extends Type {
|
|
945
|
+
isOptional;
|
|
946
|
+
constructor(type, isOptional, annotations = {}) {
|
|
947
|
+
super(type, annotations);
|
|
948
|
+
this.isOptional = isOptional;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* @since 3.10.0
|
|
952
|
+
*/
|
|
953
|
+
toJSON() {
|
|
954
|
+
return {
|
|
955
|
+
type: this.type.toJSON(),
|
|
956
|
+
isOptional: this.isOptional,
|
|
957
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* @since 3.10.0
|
|
962
|
+
*/
|
|
963
|
+
toString() {
|
|
964
|
+
return String(this.type) + (this.isOptional ? "?" : "");
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
const getRestASTs = rest => rest.map(annotatedAST => annotatedAST.type);
|
|
968
|
+
/**
|
|
969
|
+
* @category model
|
|
970
|
+
* @since 3.10.0
|
|
971
|
+
*/
|
|
972
|
+
export class TupleType {
|
|
973
|
+
elements;
|
|
974
|
+
rest;
|
|
975
|
+
isReadonly;
|
|
976
|
+
annotations;
|
|
977
|
+
/**
|
|
978
|
+
* @since 3.10.0
|
|
979
|
+
*/
|
|
980
|
+
_tag = "TupleType";
|
|
981
|
+
constructor(elements, rest, isReadonly, annotations = {}) {
|
|
982
|
+
this.elements = elements;
|
|
983
|
+
this.rest = rest;
|
|
984
|
+
this.isReadonly = isReadonly;
|
|
985
|
+
this.annotations = annotations;
|
|
986
|
+
let hasOptionalElement = false;
|
|
987
|
+
let hasIllegalRequiredElement = false;
|
|
988
|
+
for (const e of elements) {
|
|
989
|
+
if (e.isOptional) {
|
|
990
|
+
hasOptionalElement = true;
|
|
991
|
+
} else if (hasOptionalElement) {
|
|
992
|
+
hasIllegalRequiredElement = true;
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (hasIllegalRequiredElement || hasOptionalElement && rest.length > 1) {
|
|
997
|
+
throw new Error(errors_.getASTRequiredElementFollowinAnOptionalElementErrorMessage);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* @since 3.10.0
|
|
1002
|
+
*/
|
|
1003
|
+
toString() {
|
|
1004
|
+
return Option.getOrElse(getExpected(this), () => formatTuple(this));
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* @since 3.10.0
|
|
1008
|
+
*/
|
|
1009
|
+
toJSON() {
|
|
1010
|
+
return {
|
|
1011
|
+
_tag: this._tag,
|
|
1012
|
+
elements: this.elements.map(e => e.toJSON()),
|
|
1013
|
+
rest: this.rest.map(ast => ast.toJSON()),
|
|
1014
|
+
isReadonly: this.isReadonly,
|
|
1015
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
const formatTuple = ast => {
|
|
1020
|
+
const formattedElements = ast.elements.map(String).join(", ");
|
|
1021
|
+
return Arr.matchLeft(ast.rest, {
|
|
1022
|
+
onEmpty: () => `readonly [${formattedElements}]`,
|
|
1023
|
+
onNonEmpty: (head, tail) => {
|
|
1024
|
+
const formattedHead = String(head);
|
|
1025
|
+
const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead;
|
|
1026
|
+
if (tail.length > 0) {
|
|
1027
|
+
const formattedTail = tail.map(String).join(", ");
|
|
1028
|
+
if (ast.elements.length > 0) {
|
|
1029
|
+
return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`;
|
|
1030
|
+
} else {
|
|
1031
|
+
return `readonly [...${wrappedHead}[], ${formattedTail}]`;
|
|
1032
|
+
}
|
|
1033
|
+
} else {
|
|
1034
|
+
if (ast.elements.length > 0) {
|
|
1035
|
+
return `readonly [${formattedElements}, ...${wrappedHead}[]]`;
|
|
1036
|
+
} else {
|
|
1037
|
+
return `ReadonlyArray<${formattedHead}>`;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
};
|
|
1043
|
+
/**
|
|
1044
|
+
* @category guards
|
|
1045
|
+
* @since 3.10.0
|
|
1046
|
+
*/
|
|
1047
|
+
export const isTupleType = /*#__PURE__*/createASTGuard("TupleType");
|
|
1048
|
+
/**
|
|
1049
|
+
* @category model
|
|
1050
|
+
* @since 3.10.0
|
|
1051
|
+
*/
|
|
1052
|
+
export class PropertySignature extends OptionalType {
|
|
1053
|
+
name;
|
|
1054
|
+
isReadonly;
|
|
1055
|
+
constructor(name, type, isOptional, isReadonly, annotations) {
|
|
1056
|
+
super(type, isOptional, annotations);
|
|
1057
|
+
this.name = name;
|
|
1058
|
+
this.isReadonly = isReadonly;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* @since 3.10.0
|
|
1062
|
+
*/
|
|
1063
|
+
toString() {
|
|
1064
|
+
return (this.isReadonly ? "readonly " : "") + String(this.name) + (this.isOptional ? "?" : "") + ": " + this.type;
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* @since 3.10.0
|
|
1068
|
+
*/
|
|
1069
|
+
toJSON() {
|
|
1070
|
+
return {
|
|
1071
|
+
name: String(this.name),
|
|
1072
|
+
type: this.type.toJSON(),
|
|
1073
|
+
isOptional: this.isOptional,
|
|
1074
|
+
isReadonly: this.isReadonly,
|
|
1075
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* @since 3.10.0
|
|
1081
|
+
*/
|
|
1082
|
+
export const isParameter = ast => {
|
|
1083
|
+
switch (ast._tag) {
|
|
1084
|
+
case "StringKeyword":
|
|
1085
|
+
case "SymbolKeyword":
|
|
1086
|
+
case "TemplateLiteral":
|
|
1087
|
+
return true;
|
|
1088
|
+
case "Refinement":
|
|
1089
|
+
return isParameter(ast.from);
|
|
1090
|
+
}
|
|
1091
|
+
return false;
|
|
1092
|
+
};
|
|
1093
|
+
/**
|
|
1094
|
+
* @category model
|
|
1095
|
+
* @since 3.10.0
|
|
1096
|
+
*/
|
|
1097
|
+
export class IndexSignature {
|
|
1098
|
+
type;
|
|
1099
|
+
isReadonly;
|
|
1100
|
+
/**
|
|
1101
|
+
* @since 3.10.0
|
|
1102
|
+
*/
|
|
1103
|
+
parameter;
|
|
1104
|
+
constructor(parameter, type, isReadonly) {
|
|
1105
|
+
this.type = type;
|
|
1106
|
+
this.isReadonly = isReadonly;
|
|
1107
|
+
if (isParameter(parameter)) {
|
|
1108
|
+
this.parameter = parameter;
|
|
1109
|
+
} else {
|
|
1110
|
+
throw new Error(errors_.getASTIndexSignatureParameterErrorMessage);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* @since 3.10.0
|
|
1115
|
+
*/
|
|
1116
|
+
toString() {
|
|
1117
|
+
return (this.isReadonly ? "readonly " : "") + `[x: ${this.parameter}]: ${this.type}`;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* @since 3.10.0
|
|
1121
|
+
*/
|
|
1122
|
+
toJSON() {
|
|
1123
|
+
return {
|
|
1124
|
+
parameter: this.parameter.toJSON(),
|
|
1125
|
+
type: this.type.toJSON(),
|
|
1126
|
+
isReadonly: this.isReadonly
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* @category model
|
|
1132
|
+
* @since 3.10.0
|
|
1133
|
+
*/
|
|
1134
|
+
export class TypeLiteral {
|
|
1135
|
+
annotations;
|
|
1136
|
+
/**
|
|
1137
|
+
* @since 3.10.0
|
|
1138
|
+
*/
|
|
1139
|
+
_tag = "TypeLiteral";
|
|
1140
|
+
/**
|
|
1141
|
+
* @since 3.10.0
|
|
1142
|
+
*/
|
|
1143
|
+
propertySignatures;
|
|
1144
|
+
/**
|
|
1145
|
+
* @since 3.10.0
|
|
1146
|
+
*/
|
|
1147
|
+
indexSignatures;
|
|
1148
|
+
constructor(propertySignatures, indexSignatures, annotations = {}) {
|
|
1149
|
+
this.annotations = annotations;
|
|
1150
|
+
// check for duplicate property signatures
|
|
1151
|
+
const keys = {};
|
|
1152
|
+
for (let i = 0; i < propertySignatures.length; i++) {
|
|
1153
|
+
const name = propertySignatures[i].name;
|
|
1154
|
+
if (Object.prototype.hasOwnProperty.call(keys, name)) {
|
|
1155
|
+
throw new Error(errors_.getASTDuplicatePropertySignatureErrorMessage(name));
|
|
1156
|
+
}
|
|
1157
|
+
keys[name] = null;
|
|
1158
|
+
}
|
|
1159
|
+
// check for duplicate index signatures
|
|
1160
|
+
const parameters = {
|
|
1161
|
+
string: false,
|
|
1162
|
+
symbol: false
|
|
1163
|
+
};
|
|
1164
|
+
for (let i = 0; i < indexSignatures.length; i++) {
|
|
1165
|
+
const parameter = getParameterBase(indexSignatures[i].parameter);
|
|
1166
|
+
if (isStringKeyword(parameter)) {
|
|
1167
|
+
if (parameters.string) {
|
|
1168
|
+
throw new Error(errors_.getASTDuplicateIndexSignatureErrorMessage("string"));
|
|
1169
|
+
}
|
|
1170
|
+
parameters.string = true;
|
|
1171
|
+
} else if (isSymbolKeyword(parameter)) {
|
|
1172
|
+
if (parameters.symbol) {
|
|
1173
|
+
throw new Error(errors_.getASTDuplicateIndexSignatureErrorMessage("symbol"));
|
|
1174
|
+
}
|
|
1175
|
+
parameters.symbol = true;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
this.propertySignatures = propertySignatures;
|
|
1179
|
+
this.indexSignatures = indexSignatures;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* @since 3.10.0
|
|
1183
|
+
*/
|
|
1184
|
+
toString() {
|
|
1185
|
+
return Option.getOrElse(getExpected(this), () => formatTypeLiteral(this));
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* @since 3.10.0
|
|
1189
|
+
*/
|
|
1190
|
+
toJSON() {
|
|
1191
|
+
return {
|
|
1192
|
+
_tag: this._tag,
|
|
1193
|
+
propertySignatures: this.propertySignatures.map(ps => ps.toJSON()),
|
|
1194
|
+
indexSignatures: this.indexSignatures.map(ps => ps.toJSON()),
|
|
1195
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
const formatIndexSignatures = iss => iss.map(String).join("; ");
|
|
1200
|
+
const formatTypeLiteral = ast => {
|
|
1201
|
+
if (ast.propertySignatures.length > 0) {
|
|
1202
|
+
const pss = ast.propertySignatures.map(String).join("; ");
|
|
1203
|
+
if (ast.indexSignatures.length > 0) {
|
|
1204
|
+
return `{ ${pss}; ${formatIndexSignatures(ast.indexSignatures)} }`;
|
|
1205
|
+
} else {
|
|
1206
|
+
return `{ ${pss} }`;
|
|
1207
|
+
}
|
|
1208
|
+
} else {
|
|
1209
|
+
if (ast.indexSignatures.length > 0) {
|
|
1210
|
+
return `{ ${formatIndexSignatures(ast.indexSignatures)} }`;
|
|
1211
|
+
} else {
|
|
1212
|
+
return "{}";
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
/**
|
|
1217
|
+
* @category guards
|
|
1218
|
+
* @since 3.10.0
|
|
1219
|
+
*/
|
|
1220
|
+
export const isTypeLiteral = /*#__PURE__*/createASTGuard("TypeLiteral");
|
|
1221
|
+
const sortCandidates = /*#__PURE__*/Arr.sort( /*#__PURE__*/Order.mapInput(Number.Order, ast => {
|
|
1222
|
+
switch (ast._tag) {
|
|
1223
|
+
case "AnyKeyword":
|
|
1224
|
+
return 0;
|
|
1225
|
+
case "UnknownKeyword":
|
|
1226
|
+
return 1;
|
|
1227
|
+
case "ObjectKeyword":
|
|
1228
|
+
return 2;
|
|
1229
|
+
case "StringKeyword":
|
|
1230
|
+
case "NumberKeyword":
|
|
1231
|
+
case "BooleanKeyword":
|
|
1232
|
+
case "BigIntKeyword":
|
|
1233
|
+
case "SymbolKeyword":
|
|
1234
|
+
return 3;
|
|
1235
|
+
}
|
|
1236
|
+
return 4;
|
|
1237
|
+
}));
|
|
1238
|
+
const literalMap = {
|
|
1239
|
+
string: "StringKeyword",
|
|
1240
|
+
number: "NumberKeyword",
|
|
1241
|
+
boolean: "BooleanKeyword",
|
|
1242
|
+
bigint: "BigIntKeyword"
|
|
1243
|
+
};
|
|
1244
|
+
/** @internal */
|
|
1245
|
+
export const flatten = candidates => Arr.flatMap(candidates, ast => isUnion(ast) ? flatten(ast.types) : [ast]);
|
|
1246
|
+
/** @internal */
|
|
1247
|
+
export const unify = candidates => {
|
|
1248
|
+
const cs = sortCandidates(candidates);
|
|
1249
|
+
const out = [];
|
|
1250
|
+
const uniques = {};
|
|
1251
|
+
const literals = [];
|
|
1252
|
+
for (const ast of cs) {
|
|
1253
|
+
switch (ast._tag) {
|
|
1254
|
+
case "NeverKeyword":
|
|
1255
|
+
break;
|
|
1256
|
+
case "AnyKeyword":
|
|
1257
|
+
return [anyKeyword];
|
|
1258
|
+
case "UnknownKeyword":
|
|
1259
|
+
return [unknownKeyword];
|
|
1260
|
+
// uniques
|
|
1261
|
+
case "ObjectKeyword":
|
|
1262
|
+
case "UndefinedKeyword":
|
|
1263
|
+
case "VoidKeyword":
|
|
1264
|
+
case "StringKeyword":
|
|
1265
|
+
case "NumberKeyword":
|
|
1266
|
+
case "BooleanKeyword":
|
|
1267
|
+
case "BigIntKeyword":
|
|
1268
|
+
case "SymbolKeyword":
|
|
1269
|
+
{
|
|
1270
|
+
if (!uniques[ast._tag]) {
|
|
1271
|
+
uniques[ast._tag] = ast;
|
|
1272
|
+
out.push(ast);
|
|
1273
|
+
}
|
|
1274
|
+
break;
|
|
1275
|
+
}
|
|
1276
|
+
case "Literal":
|
|
1277
|
+
{
|
|
1278
|
+
const type = typeof ast.literal;
|
|
1279
|
+
switch (type) {
|
|
1280
|
+
case "string":
|
|
1281
|
+
case "number":
|
|
1282
|
+
case "bigint":
|
|
1283
|
+
case "boolean":
|
|
1284
|
+
{
|
|
1285
|
+
const _tag = literalMap[type];
|
|
1286
|
+
if (!uniques[_tag] && !literals.includes(ast.literal)) {
|
|
1287
|
+
literals.push(ast.literal);
|
|
1288
|
+
out.push(ast);
|
|
1289
|
+
}
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
// null
|
|
1293
|
+
case "object":
|
|
1294
|
+
{
|
|
1295
|
+
if (!literals.includes(ast.literal)) {
|
|
1296
|
+
literals.push(ast.literal);
|
|
1297
|
+
out.push(ast);
|
|
1298
|
+
}
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
case "UniqueSymbol":
|
|
1305
|
+
{
|
|
1306
|
+
if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) {
|
|
1307
|
+
literals.push(ast.symbol);
|
|
1308
|
+
out.push(ast);
|
|
1309
|
+
}
|
|
1310
|
+
break;
|
|
1311
|
+
}
|
|
1312
|
+
case "TupleType":
|
|
1313
|
+
{
|
|
1314
|
+
if (!uniques["ObjectKeyword"]) {
|
|
1315
|
+
out.push(ast);
|
|
1316
|
+
}
|
|
1317
|
+
break;
|
|
1318
|
+
}
|
|
1319
|
+
case "TypeLiteral":
|
|
1320
|
+
{
|
|
1321
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) {
|
|
1322
|
+
if (!uniques["{}"]) {
|
|
1323
|
+
uniques["{}"] = ast;
|
|
1324
|
+
out.push(ast);
|
|
1325
|
+
}
|
|
1326
|
+
} else if (!uniques["ObjectKeyword"]) {
|
|
1327
|
+
out.push(ast);
|
|
1328
|
+
}
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
default:
|
|
1332
|
+
out.push(ast);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
return out;
|
|
1336
|
+
};
|
|
1337
|
+
/**
|
|
1338
|
+
* @category model
|
|
1339
|
+
* @since 3.10.0
|
|
1340
|
+
*/
|
|
1341
|
+
export class Union {
|
|
1342
|
+
types;
|
|
1343
|
+
annotations;
|
|
1344
|
+
static make = (types, annotations) => {
|
|
1345
|
+
return isMembers(types) ? new Union(types, annotations) : types.length === 1 ? types[0] : neverKeyword;
|
|
1346
|
+
};
|
|
1347
|
+
/** @internal */
|
|
1348
|
+
static unify = (candidates, annotations) => {
|
|
1349
|
+
return Union.make(unify(flatten(candidates)), annotations);
|
|
1350
|
+
};
|
|
1351
|
+
/**
|
|
1352
|
+
* @since 3.10.0
|
|
1353
|
+
*/
|
|
1354
|
+
_tag = "Union";
|
|
1355
|
+
constructor(types, annotations = {}) {
|
|
1356
|
+
this.types = types;
|
|
1357
|
+
this.annotations = annotations;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* @since 3.10.0
|
|
1361
|
+
*/
|
|
1362
|
+
toString() {
|
|
1363
|
+
return Option.getOrElse(getExpected(this), () => this.types.map(String).join(" | "));
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* @since 3.10.0
|
|
1367
|
+
*/
|
|
1368
|
+
toJSON() {
|
|
1369
|
+
return {
|
|
1370
|
+
_tag: this._tag,
|
|
1371
|
+
types: this.types.map(ast => ast.toJSON()),
|
|
1372
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
/** @internal */
|
|
1377
|
+
export const mapMembers = (members, f) => members.map(f);
|
|
1378
|
+
/** @internal */
|
|
1379
|
+
export const isMembers = as => as.length > 1;
|
|
1380
|
+
/**
|
|
1381
|
+
* @category guards
|
|
1382
|
+
* @since 3.10.0
|
|
1383
|
+
*/
|
|
1384
|
+
export const isUnion = /*#__PURE__*/createASTGuard("Union");
|
|
1385
|
+
const toJSONMemoMap = /*#__PURE__*/globalValue( /*#__PURE__*/Symbol.for("effect/Schema/AST/toJSONMemoMap"), () => new WeakMap());
|
|
1386
|
+
/**
|
|
1387
|
+
* @category model
|
|
1388
|
+
* @since 3.10.0
|
|
1389
|
+
*/
|
|
1390
|
+
export class Suspend {
|
|
1391
|
+
f;
|
|
1392
|
+
annotations;
|
|
1393
|
+
/**
|
|
1394
|
+
* @since 3.10.0
|
|
1395
|
+
*/
|
|
1396
|
+
_tag = "Suspend";
|
|
1397
|
+
constructor(f, annotations = {}) {
|
|
1398
|
+
this.f = f;
|
|
1399
|
+
this.annotations = annotations;
|
|
1400
|
+
this.f = util_.memoizeThunk(f);
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* @since 3.10.0
|
|
1404
|
+
*/
|
|
1405
|
+
toString() {
|
|
1406
|
+
return getExpected(this).pipe(Option.orElse(() => Option.flatMap(Option.liftThrowable(this.f)(), ast => getExpected(ast))), Option.getOrElse(() => "<suspended schema>"));
|
|
1407
|
+
}
|
|
1408
|
+
/**
|
|
1409
|
+
* @since 3.10.0
|
|
1410
|
+
*/
|
|
1411
|
+
toJSON() {
|
|
1412
|
+
const ast = this.f();
|
|
1413
|
+
let out = toJSONMemoMap.get(ast);
|
|
1414
|
+
if (out) {
|
|
1415
|
+
return out;
|
|
1416
|
+
}
|
|
1417
|
+
toJSONMemoMap.set(ast, {
|
|
1418
|
+
_tag: this._tag
|
|
1419
|
+
});
|
|
1420
|
+
out = {
|
|
1421
|
+
_tag: this._tag,
|
|
1422
|
+
ast: ast.toJSON(),
|
|
1423
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1424
|
+
};
|
|
1425
|
+
toJSONMemoMap.set(ast, out);
|
|
1426
|
+
return out;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* @category guards
|
|
1431
|
+
* @since 3.10.0
|
|
1432
|
+
*/
|
|
1433
|
+
export const isSuspend = /*#__PURE__*/createASTGuard("Suspend");
|
|
1434
|
+
/**
|
|
1435
|
+
* @category model
|
|
1436
|
+
* @since 3.10.0
|
|
1437
|
+
*/
|
|
1438
|
+
export class Refinement {
|
|
1439
|
+
from;
|
|
1440
|
+
filter;
|
|
1441
|
+
annotations;
|
|
1442
|
+
/**
|
|
1443
|
+
* @since 3.10.0
|
|
1444
|
+
*/
|
|
1445
|
+
_tag = "Refinement";
|
|
1446
|
+
constructor(from, filter, annotations = {}) {
|
|
1447
|
+
this.from = from;
|
|
1448
|
+
this.filter = filter;
|
|
1449
|
+
this.annotations = annotations;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* @since 3.10.0
|
|
1453
|
+
*/
|
|
1454
|
+
toString() {
|
|
1455
|
+
return Option.getOrElse(getExpected(this), () => `{ ${this.from} | filter }`);
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* @since 3.10.0
|
|
1459
|
+
*/
|
|
1460
|
+
toJSON() {
|
|
1461
|
+
return {
|
|
1462
|
+
_tag: this._tag,
|
|
1463
|
+
from: this.from.toJSON(),
|
|
1464
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* @category guards
|
|
1470
|
+
* @since 3.10.0
|
|
1471
|
+
*/
|
|
1472
|
+
export const isRefinement = /*#__PURE__*/createASTGuard("Refinement");
|
|
1473
|
+
/**
|
|
1474
|
+
* @since 3.10.0
|
|
1475
|
+
*/
|
|
1476
|
+
export const defaultParseOption = {};
|
|
1477
|
+
/**
|
|
1478
|
+
* @category model
|
|
1479
|
+
* @since 3.10.0
|
|
1480
|
+
*/
|
|
1481
|
+
export class Transformation {
|
|
1482
|
+
from;
|
|
1483
|
+
to;
|
|
1484
|
+
transformation;
|
|
1485
|
+
annotations;
|
|
1486
|
+
/**
|
|
1487
|
+
* @since 3.10.0
|
|
1488
|
+
*/
|
|
1489
|
+
_tag = "Transformation";
|
|
1490
|
+
constructor(from, to, transformation, annotations = {}) {
|
|
1491
|
+
this.from = from;
|
|
1492
|
+
this.to = to;
|
|
1493
|
+
this.transformation = transformation;
|
|
1494
|
+
this.annotations = annotations;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* @since 3.10.0
|
|
1498
|
+
*/
|
|
1499
|
+
toString() {
|
|
1500
|
+
return Option.getOrElse(getExpected(this), () => `(${String(this.from)} <-> ${String(this.to)})`);
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* @since 3.10.0
|
|
1504
|
+
*/
|
|
1505
|
+
toJSON() {
|
|
1506
|
+
return {
|
|
1507
|
+
_tag: this._tag,
|
|
1508
|
+
from: this.from.toJSON(),
|
|
1509
|
+
to: this.to.toJSON(),
|
|
1510
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* @category guards
|
|
1516
|
+
* @since 3.10.0
|
|
1517
|
+
*/
|
|
1518
|
+
export const isTransformation = /*#__PURE__*/createASTGuard("Transformation");
|
|
1519
|
+
/**
|
|
1520
|
+
* @category model
|
|
1521
|
+
* @since 3.10.0
|
|
1522
|
+
*/
|
|
1523
|
+
export class FinalTransformation {
|
|
1524
|
+
decode;
|
|
1525
|
+
encode;
|
|
1526
|
+
/**
|
|
1527
|
+
* @since 3.10.0
|
|
1528
|
+
*/
|
|
1529
|
+
_tag = "FinalTransformation";
|
|
1530
|
+
constructor(decode, encode) {
|
|
1531
|
+
this.decode = decode;
|
|
1532
|
+
this.encode = encode;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
const createTransformationGuard = tag => ast => ast._tag === tag;
|
|
1536
|
+
/**
|
|
1537
|
+
* @category guards
|
|
1538
|
+
* @since 3.10.0
|
|
1539
|
+
*/
|
|
1540
|
+
export const isFinalTransformation = /*#__PURE__*/createTransformationGuard("FinalTransformation");
|
|
1541
|
+
/**
|
|
1542
|
+
* @category model
|
|
1543
|
+
* @since 3.10.0
|
|
1544
|
+
*/
|
|
1545
|
+
export class ComposeTransformation {
|
|
1546
|
+
/**
|
|
1547
|
+
* @since 3.10.0
|
|
1548
|
+
*/
|
|
1549
|
+
_tag = "ComposeTransformation";
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* @category constructors
|
|
1553
|
+
* @since 3.10.0
|
|
1554
|
+
*/
|
|
1555
|
+
export const composeTransformation = /*#__PURE__*/new ComposeTransformation();
|
|
1556
|
+
/**
|
|
1557
|
+
* @category guards
|
|
1558
|
+
* @since 3.10.0
|
|
1559
|
+
*/
|
|
1560
|
+
export const isComposeTransformation = /*#__PURE__*/createTransformationGuard("ComposeTransformation");
|
|
1561
|
+
/**
|
|
1562
|
+
* Represents a `PropertySignature -> PropertySignature` transformation
|
|
1563
|
+
*
|
|
1564
|
+
* The semantic of `decode` is:
|
|
1565
|
+
* - `none()` represents the absence of the key/value pair
|
|
1566
|
+
* - `some(value)` represents the presence of the key/value pair
|
|
1567
|
+
*
|
|
1568
|
+
* The semantic of `encode` is:
|
|
1569
|
+
* - `none()` you don't want to output the key/value pair
|
|
1570
|
+
* - `some(value)` you want to output the key/value pair
|
|
1571
|
+
*
|
|
1572
|
+
* @category model
|
|
1573
|
+
* @since 3.10.0
|
|
1574
|
+
*/
|
|
1575
|
+
export class PropertySignatureTransformation {
|
|
1576
|
+
from;
|
|
1577
|
+
to;
|
|
1578
|
+
decode;
|
|
1579
|
+
encode;
|
|
1580
|
+
constructor(from, to, decode, encode) {
|
|
1581
|
+
this.from = from;
|
|
1582
|
+
this.to = to;
|
|
1583
|
+
this.decode = decode;
|
|
1584
|
+
this.encode = encode;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
const isRenamingPropertySignatureTransformation = t => t.decode === identity && t.encode === identity;
|
|
1588
|
+
/**
|
|
1589
|
+
* @category model
|
|
1590
|
+
* @since 3.10.0
|
|
1591
|
+
*/
|
|
1592
|
+
export class TypeLiteralTransformation {
|
|
1593
|
+
propertySignatureTransformations;
|
|
1594
|
+
/**
|
|
1595
|
+
* @since 3.10.0
|
|
1596
|
+
*/
|
|
1597
|
+
_tag = "TypeLiteralTransformation";
|
|
1598
|
+
constructor(propertySignatureTransformations) {
|
|
1599
|
+
this.propertySignatureTransformations = propertySignatureTransformations;
|
|
1600
|
+
// check for duplicate property signature transformations
|
|
1601
|
+
const fromKeys = {};
|
|
1602
|
+
const toKeys = {};
|
|
1603
|
+
for (const pst of propertySignatureTransformations) {
|
|
1604
|
+
const from = pst.from;
|
|
1605
|
+
if (fromKeys[from]) {
|
|
1606
|
+
throw new Error(errors_.getASTDuplicatePropertySignatureTransformationErrorMessage(from));
|
|
1607
|
+
}
|
|
1608
|
+
fromKeys[from] = true;
|
|
1609
|
+
const to = pst.to;
|
|
1610
|
+
if (toKeys[to]) {
|
|
1611
|
+
throw new Error(errors_.getASTDuplicatePropertySignatureTransformationErrorMessage(to));
|
|
1612
|
+
}
|
|
1613
|
+
toKeys[to] = true;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* @category guards
|
|
1619
|
+
* @since 3.10.0
|
|
1620
|
+
*/
|
|
1621
|
+
export const isTypeLiteralTransformation = /*#__PURE__*/createTransformationGuard("TypeLiteralTransformation");
|
|
1622
|
+
// -------------------------------------------------------------------------------------
|
|
1623
|
+
// API
|
|
1624
|
+
// -------------------------------------------------------------------------------------
|
|
1625
|
+
/**
|
|
1626
|
+
* Merges a set of new annotations with existing ones, potentially overwriting
|
|
1627
|
+
* any duplicates.
|
|
1628
|
+
*
|
|
1629
|
+
* @since 3.10.0
|
|
1630
|
+
*/
|
|
1631
|
+
export const annotations = (ast, annotations) => {
|
|
1632
|
+
const d = Object.getOwnPropertyDescriptors(ast);
|
|
1633
|
+
d.annotations.value = {
|
|
1634
|
+
...ast.annotations,
|
|
1635
|
+
...annotations
|
|
1636
|
+
};
|
|
1637
|
+
return Object.create(Object.getPrototypeOf(ast), d);
|
|
1638
|
+
};
|
|
1639
|
+
/**
|
|
1640
|
+
* Equivalent at runtime to the TypeScript type-level `keyof` operator.
|
|
1641
|
+
*
|
|
1642
|
+
* @since 3.10.0
|
|
1643
|
+
*/
|
|
1644
|
+
export const keyof = ast => Union.unify(_keyof(ast));
|
|
1645
|
+
const STRING_KEYWORD_PATTERN = ".*";
|
|
1646
|
+
const NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
1647
|
+
/**
|
|
1648
|
+
* @since 3.10.0
|
|
1649
|
+
*/
|
|
1650
|
+
export const getTemplateLiteralRegExp = ast => {
|
|
1651
|
+
let pattern = `^${regexp.escape(ast.head)}`;
|
|
1652
|
+
for (const span of ast.spans) {
|
|
1653
|
+
if (isStringKeyword(span.type)) {
|
|
1654
|
+
pattern += STRING_KEYWORD_PATTERN;
|
|
1655
|
+
} else if (isNumberKeyword(span.type)) {
|
|
1656
|
+
pattern += NUMBER_KEYWORD_PATTERN;
|
|
1657
|
+
}
|
|
1658
|
+
pattern += regexp.escape(span.literal);
|
|
1659
|
+
}
|
|
1660
|
+
pattern += "$";
|
|
1661
|
+
return new RegExp(pattern);
|
|
1662
|
+
};
|
|
1663
|
+
/**
|
|
1664
|
+
* @since 3.10.0
|
|
1665
|
+
*/
|
|
1666
|
+
export const getTemplateLiteralCapturingRegExp = ast => {
|
|
1667
|
+
let pattern = `^`;
|
|
1668
|
+
if (ast.head !== "") {
|
|
1669
|
+
pattern += `(${regexp.escape(ast.head)})`;
|
|
1670
|
+
}
|
|
1671
|
+
for (const span of ast.spans) {
|
|
1672
|
+
if (isStringKeyword(span.type)) {
|
|
1673
|
+
pattern += `(${STRING_KEYWORD_PATTERN})`;
|
|
1674
|
+
} else if (isNumberKeyword(span.type)) {
|
|
1675
|
+
pattern += `(${NUMBER_KEYWORD_PATTERN})`;
|
|
1676
|
+
}
|
|
1677
|
+
if (span.literal !== "") {
|
|
1678
|
+
pattern += `(${regexp.escape(span.literal)})`;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
pattern += "$";
|
|
1682
|
+
return new RegExp(pattern);
|
|
1683
|
+
};
|
|
1684
|
+
/**
|
|
1685
|
+
* @since 3.10.0
|
|
1686
|
+
*/
|
|
1687
|
+
export const getPropertySignatures = ast => {
|
|
1688
|
+
switch (ast._tag) {
|
|
1689
|
+
case "Declaration":
|
|
1690
|
+
{
|
|
1691
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1692
|
+
if (Option.isSome(annotation)) {
|
|
1693
|
+
return getPropertySignatures(annotation.value);
|
|
1694
|
+
}
|
|
1695
|
+
break;
|
|
1696
|
+
}
|
|
1697
|
+
case "TypeLiteral":
|
|
1698
|
+
return ast.propertySignatures.slice();
|
|
1699
|
+
case "Suspend":
|
|
1700
|
+
return getPropertySignatures(ast.f());
|
|
1701
|
+
}
|
|
1702
|
+
return getPropertyKeys(ast).map(name => getPropertyKeyIndexedAccess(ast, name));
|
|
1703
|
+
};
|
|
1704
|
+
/** @internal */
|
|
1705
|
+
export const getNumberIndexedAccess = ast => {
|
|
1706
|
+
switch (ast._tag) {
|
|
1707
|
+
case "TupleType":
|
|
1708
|
+
{
|
|
1709
|
+
let hasOptional = false;
|
|
1710
|
+
let out = [];
|
|
1711
|
+
for (const e of ast.elements) {
|
|
1712
|
+
if (e.isOptional) {
|
|
1713
|
+
hasOptional = true;
|
|
1714
|
+
}
|
|
1715
|
+
out.push(e.type);
|
|
1716
|
+
}
|
|
1717
|
+
if (hasOptional) {
|
|
1718
|
+
out.push(undefinedKeyword);
|
|
1719
|
+
}
|
|
1720
|
+
out = out.concat(getRestASTs(ast.rest));
|
|
1721
|
+
return Union.make(out);
|
|
1722
|
+
}
|
|
1723
|
+
case "Refinement":
|
|
1724
|
+
return getNumberIndexedAccess(ast.from);
|
|
1725
|
+
case "Union":
|
|
1726
|
+
return Union.make(ast.types.map(getNumberIndexedAccess));
|
|
1727
|
+
case "Suspend":
|
|
1728
|
+
return getNumberIndexedAccess(ast.f());
|
|
1729
|
+
}
|
|
1730
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1731
|
+
};
|
|
1732
|
+
const getTypeLiteralPropertySignature = (ast, name) => {
|
|
1733
|
+
// from property signatures...
|
|
1734
|
+
const ops = Arr.findFirst(ast.propertySignatures, ps => ps.name === name);
|
|
1735
|
+
if (Option.isSome(ops)) {
|
|
1736
|
+
return ops.value;
|
|
1737
|
+
}
|
|
1738
|
+
// from index signatures...
|
|
1739
|
+
if (Predicate.isString(name)) {
|
|
1740
|
+
let out = undefined;
|
|
1741
|
+
for (const is of ast.indexSignatures) {
|
|
1742
|
+
const parameterBase = getParameterBase(is.parameter);
|
|
1743
|
+
switch (parameterBase._tag) {
|
|
1744
|
+
case "TemplateLiteral":
|
|
1745
|
+
{
|
|
1746
|
+
const regex = getTemplateLiteralRegExp(parameterBase);
|
|
1747
|
+
if (regex.test(name)) {
|
|
1748
|
+
return new PropertySignature(name, is.type, false, true);
|
|
1749
|
+
}
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
case "StringKeyword":
|
|
1753
|
+
{
|
|
1754
|
+
if (out === undefined) {
|
|
1755
|
+
out = new PropertySignature(name, is.type, false, true);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
if (out) {
|
|
1761
|
+
return out;
|
|
1762
|
+
}
|
|
1763
|
+
} else if (Predicate.isSymbol(name)) {
|
|
1764
|
+
for (const is of ast.indexSignatures) {
|
|
1765
|
+
const parameterBase = getParameterBase(is.parameter);
|
|
1766
|
+
if (isSymbolKeyword(parameterBase)) {
|
|
1767
|
+
return new PropertySignature(name, is.type, false, true);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
/** @internal */
|
|
1773
|
+
export const getPropertyKeyIndexedAccess = (ast, name) => {
|
|
1774
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1775
|
+
if (Option.isSome(annotation)) {
|
|
1776
|
+
return getPropertyKeyIndexedAccess(annotation.value, name);
|
|
1777
|
+
}
|
|
1778
|
+
switch (ast._tag) {
|
|
1779
|
+
case "TypeLiteral":
|
|
1780
|
+
{
|
|
1781
|
+
const ps = getTypeLiteralPropertySignature(ast, name);
|
|
1782
|
+
if (ps) {
|
|
1783
|
+
return ps;
|
|
1784
|
+
}
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
case "Union":
|
|
1788
|
+
return new PropertySignature(name, Union.make(ast.types.map(ast => getPropertyKeyIndexedAccess(ast, name).type)), false, true);
|
|
1789
|
+
case "Suspend":
|
|
1790
|
+
return getPropertyKeyIndexedAccess(ast.f(), name);
|
|
1791
|
+
case "Refinement":
|
|
1792
|
+
return getPropertyKeyIndexedAccess(ast.from, name);
|
|
1793
|
+
}
|
|
1794
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1795
|
+
};
|
|
1796
|
+
const getPropertyKeys = ast => {
|
|
1797
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1798
|
+
if (Option.isSome(annotation)) {
|
|
1799
|
+
return getPropertyKeys(annotation.value);
|
|
1800
|
+
}
|
|
1801
|
+
switch (ast._tag) {
|
|
1802
|
+
case "TypeLiteral":
|
|
1803
|
+
return ast.propertySignatures.map(ps => ps.name);
|
|
1804
|
+
case "Suspend":
|
|
1805
|
+
return getPropertyKeys(ast.f());
|
|
1806
|
+
case "Union":
|
|
1807
|
+
return ast.types.slice(1).reduce((out, ast) => Arr.intersection(out, getPropertyKeys(ast)), getPropertyKeys(ast.types[0]));
|
|
1808
|
+
case "Transformation":
|
|
1809
|
+
return getPropertyKeys(ast.to);
|
|
1810
|
+
}
|
|
1811
|
+
return [];
|
|
1812
|
+
};
|
|
1813
|
+
/** @internal */
|
|
1814
|
+
export const record = (key, value) => {
|
|
1815
|
+
const propertySignatures = [];
|
|
1816
|
+
const indexSignatures = [];
|
|
1817
|
+
const go = key => {
|
|
1818
|
+
switch (key._tag) {
|
|
1819
|
+
case "NeverKeyword":
|
|
1820
|
+
break;
|
|
1821
|
+
case "StringKeyword":
|
|
1822
|
+
case "SymbolKeyword":
|
|
1823
|
+
case "TemplateLiteral":
|
|
1824
|
+
case "Refinement":
|
|
1825
|
+
indexSignatures.push(new IndexSignature(key, value, true));
|
|
1826
|
+
break;
|
|
1827
|
+
case "Literal":
|
|
1828
|
+
if (Predicate.isString(key.literal) || Predicate.isNumber(key.literal)) {
|
|
1829
|
+
propertySignatures.push(new PropertySignature(key.literal, value, false, true));
|
|
1830
|
+
} else {
|
|
1831
|
+
throw new Error(errors_.getASTUnsupportedLiteral(key.literal));
|
|
1832
|
+
}
|
|
1833
|
+
break;
|
|
1834
|
+
case "Enums":
|
|
1835
|
+
{
|
|
1836
|
+
for (const [_, name] of key.enums) {
|
|
1837
|
+
propertySignatures.push(new PropertySignature(name, value, false, true));
|
|
1838
|
+
}
|
|
1839
|
+
break;
|
|
1840
|
+
}
|
|
1841
|
+
case "UniqueSymbol":
|
|
1842
|
+
propertySignatures.push(new PropertySignature(key.symbol, value, false, true));
|
|
1843
|
+
break;
|
|
1844
|
+
case "Union":
|
|
1845
|
+
key.types.forEach(go);
|
|
1846
|
+
break;
|
|
1847
|
+
default:
|
|
1848
|
+
throw new Error(errors_.getASTUnsupportedKeySchema(key));
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
go(key);
|
|
1852
|
+
return {
|
|
1853
|
+
propertySignatures,
|
|
1854
|
+
indexSignatures
|
|
1855
|
+
};
|
|
1856
|
+
};
|
|
1857
|
+
/**
|
|
1858
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Pick`.
|
|
1859
|
+
*
|
|
1860
|
+
* @since 3.10.0
|
|
1861
|
+
*/
|
|
1862
|
+
export const pick = (ast, keys) => {
|
|
1863
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1864
|
+
if (Option.isSome(annotation)) {
|
|
1865
|
+
return pick(annotation.value, keys);
|
|
1866
|
+
}
|
|
1867
|
+
switch (ast._tag) {
|
|
1868
|
+
case "TypeLiteral":
|
|
1869
|
+
{
|
|
1870
|
+
const pss = [];
|
|
1871
|
+
const names = {};
|
|
1872
|
+
for (const ps of ast.propertySignatures) {
|
|
1873
|
+
names[ps.name] = null;
|
|
1874
|
+
if (keys.includes(ps.name)) {
|
|
1875
|
+
pss.push(ps);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
for (const key of keys) {
|
|
1879
|
+
if (!(key in names)) {
|
|
1880
|
+
const ps = getTypeLiteralPropertySignature(ast, key);
|
|
1881
|
+
if (ps) {
|
|
1882
|
+
pss.push(ps);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
return new TypeLiteral(pss, []);
|
|
1887
|
+
}
|
|
1888
|
+
case "Union":
|
|
1889
|
+
return new TypeLiteral(keys.map(name => getPropertyKeyIndexedAccess(ast, name)), []);
|
|
1890
|
+
case "Suspend":
|
|
1891
|
+
return pick(ast.f(), keys);
|
|
1892
|
+
case "Refinement":
|
|
1893
|
+
return pick(ast.from, keys);
|
|
1894
|
+
case "Transformation":
|
|
1895
|
+
{
|
|
1896
|
+
switch (ast.transformation._tag) {
|
|
1897
|
+
case "ComposeTransformation":
|
|
1898
|
+
return new Transformation(pick(ast.from, keys), pick(ast.to, keys), composeTransformation);
|
|
1899
|
+
case "TypeLiteralTransformation":
|
|
1900
|
+
{
|
|
1901
|
+
const ts = [];
|
|
1902
|
+
const fromKeys = [];
|
|
1903
|
+
for (const k of keys) {
|
|
1904
|
+
const t = ast.transformation.propertySignatureTransformations.find(t => t.to === k);
|
|
1905
|
+
if (t) {
|
|
1906
|
+
ts.push(t);
|
|
1907
|
+
fromKeys.push(t.from);
|
|
1908
|
+
} else {
|
|
1909
|
+
fromKeys.push(k);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
return Arr.isNonEmptyReadonlyArray(ts) ? new Transformation(pick(ast.from, fromKeys), pick(ast.to, keys), new TypeLiteralTransformation(ts)) : pick(ast.from, fromKeys);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1918
|
+
};
|
|
1919
|
+
/**
|
|
1920
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Omit`.
|
|
1921
|
+
*
|
|
1922
|
+
* @since 3.10.0
|
|
1923
|
+
*/
|
|
1924
|
+
export const omit = (ast, keys) => pick(ast, getPropertyKeys(ast).filter(name => !keys.includes(name)));
|
|
1925
|
+
/** @internal */
|
|
1926
|
+
export const orUndefined = ast => Union.make([ast, undefinedKeyword]);
|
|
1927
|
+
/**
|
|
1928
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Partial`.
|
|
1929
|
+
*
|
|
1930
|
+
* @since 3.10.0
|
|
1931
|
+
*/
|
|
1932
|
+
export const partial = (ast, options) => {
|
|
1933
|
+
const exact = options?.exact === true;
|
|
1934
|
+
switch (ast._tag) {
|
|
1935
|
+
case "TupleType":
|
|
1936
|
+
return new TupleType(ast.elements.map(e => new OptionalType(exact ? e.type : orUndefined(e.type), true)), Arr.match(ast.rest, {
|
|
1937
|
+
onEmpty: () => ast.rest,
|
|
1938
|
+
onNonEmpty: rest => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))]
|
|
1939
|
+
}), ast.isReadonly);
|
|
1940
|
+
case "TypeLiteral":
|
|
1941
|
+
return new TypeLiteral(ast.propertySignatures.map(ps => new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)), ast.indexSignatures.map(is => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly)));
|
|
1942
|
+
case "Union":
|
|
1943
|
+
return Union.make(ast.types.map(member => partial(member, options)));
|
|
1944
|
+
case "Suspend":
|
|
1945
|
+
return new Suspend(() => partial(ast.f(), options));
|
|
1946
|
+
case "Declaration":
|
|
1947
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1948
|
+
case "Refinement":
|
|
1949
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1950
|
+
case "Transformation":
|
|
1951
|
+
{
|
|
1952
|
+
if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) {
|
|
1953
|
+
return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation);
|
|
1954
|
+
}
|
|
1955
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
return ast;
|
|
1959
|
+
};
|
|
1960
|
+
/**
|
|
1961
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Required`.
|
|
1962
|
+
*
|
|
1963
|
+
* @since 3.10.0
|
|
1964
|
+
*/
|
|
1965
|
+
export const required = ast => {
|
|
1966
|
+
switch (ast._tag) {
|
|
1967
|
+
case "TupleType":
|
|
1968
|
+
return new TupleType(ast.elements.map(e => new OptionalType(e.type, false)), ast.rest, ast.isReadonly);
|
|
1969
|
+
case "TypeLiteral":
|
|
1970
|
+
return new TypeLiteral(ast.propertySignatures.map(f => new PropertySignature(f.name, f.type, false, f.isReadonly, f.annotations)), ast.indexSignatures);
|
|
1971
|
+
case "Union":
|
|
1972
|
+
return Union.make(ast.types.map(member => required(member)));
|
|
1973
|
+
case "Suspend":
|
|
1974
|
+
return new Suspend(() => required(ast.f()));
|
|
1975
|
+
case "Declaration":
|
|
1976
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1977
|
+
case "Refinement":
|
|
1978
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1979
|
+
case "Transformation":
|
|
1980
|
+
{
|
|
1981
|
+
if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) {
|
|
1982
|
+
return new Transformation(required(ast.from), required(ast.to), ast.transformation);
|
|
1983
|
+
}
|
|
1984
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
return ast;
|
|
1988
|
+
};
|
|
1989
|
+
/**
|
|
1990
|
+
* Creates a new AST with shallow mutability applied to its properties.
|
|
1991
|
+
*
|
|
1992
|
+
* @param ast - The original AST to make properties mutable (shallowly).
|
|
1993
|
+
*
|
|
1994
|
+
* @since 3.10.0
|
|
1995
|
+
*/
|
|
1996
|
+
export const mutable = ast => {
|
|
1997
|
+
switch (ast._tag) {
|
|
1998
|
+
case "TupleType":
|
|
1999
|
+
return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations);
|
|
2000
|
+
case "TypeLiteral":
|
|
2001
|
+
{
|
|
2002
|
+
const propertySignatures = changeMap(ast.propertySignatures, ps => ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations));
|
|
2003
|
+
const indexSignatures = changeMap(ast.indexSignatures, is => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false));
|
|
2004
|
+
return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations);
|
|
2005
|
+
}
|
|
2006
|
+
case "Union":
|
|
2007
|
+
{
|
|
2008
|
+
const types = changeMap(ast.types, mutable);
|
|
2009
|
+
return types === ast.types ? ast : Union.make(types, ast.annotations);
|
|
2010
|
+
}
|
|
2011
|
+
case "Suspend":
|
|
2012
|
+
return new Suspend(() => mutable(ast.f()), ast.annotations);
|
|
2013
|
+
case "Refinement":
|
|
2014
|
+
{
|
|
2015
|
+
const from = mutable(ast.from);
|
|
2016
|
+
return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations);
|
|
2017
|
+
}
|
|
2018
|
+
case "Transformation":
|
|
2019
|
+
{
|
|
2020
|
+
const from = mutable(ast.from);
|
|
2021
|
+
const to = mutable(ast.to);
|
|
2022
|
+
return from === ast.from && to === ast.to ? ast : new Transformation(from, to, ast.transformation, ast.annotations);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
return ast;
|
|
2026
|
+
};
|
|
2027
|
+
/**
|
|
2028
|
+
* @since 3.10.0
|
|
2029
|
+
*/
|
|
2030
|
+
export const getCompiler = match => {
|
|
2031
|
+
const compile = (ast, path) => match[ast._tag](ast, compile, path);
|
|
2032
|
+
return compile;
|
|
2033
|
+
};
|
|
2034
|
+
/**
|
|
2035
|
+
* @since 3.10.0
|
|
2036
|
+
*/
|
|
2037
|
+
export const typeAST = ast => {
|
|
2038
|
+
switch (ast._tag) {
|
|
2039
|
+
case "Declaration":
|
|
2040
|
+
{
|
|
2041
|
+
const typeParameters = changeMap(ast.typeParameters, typeAST);
|
|
2042
|
+
return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations);
|
|
2043
|
+
}
|
|
2044
|
+
case "TupleType":
|
|
2045
|
+
{
|
|
2046
|
+
const elements = changeMap(ast.elements, e => {
|
|
2047
|
+
const type = typeAST(e.type);
|
|
2048
|
+
return type === e.type ? e : new OptionalType(type, e.isOptional);
|
|
2049
|
+
});
|
|
2050
|
+
const restASTs = getRestASTs(ast.rest);
|
|
2051
|
+
const rest = changeMap(restASTs, typeAST);
|
|
2052
|
+
return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map(type => new Type(type)), ast.isReadonly, ast.annotations);
|
|
2053
|
+
}
|
|
2054
|
+
case "TypeLiteral":
|
|
2055
|
+
{
|
|
2056
|
+
const propertySignatures = changeMap(ast.propertySignatures, p => {
|
|
2057
|
+
const type = typeAST(p.type);
|
|
2058
|
+
return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly);
|
|
2059
|
+
});
|
|
2060
|
+
const indexSignatures = changeMap(ast.indexSignatures, is => {
|
|
2061
|
+
const type = typeAST(is.type);
|
|
2062
|
+
return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly);
|
|
2063
|
+
});
|
|
2064
|
+
return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations);
|
|
2065
|
+
}
|
|
2066
|
+
case "Union":
|
|
2067
|
+
{
|
|
2068
|
+
const types = changeMap(ast.types, typeAST);
|
|
2069
|
+
return types === ast.types ? ast : Union.make(types, ast.annotations);
|
|
2070
|
+
}
|
|
2071
|
+
case "Suspend":
|
|
2072
|
+
return new Suspend(() => typeAST(ast.f()), ast.annotations);
|
|
2073
|
+
case "Refinement":
|
|
2074
|
+
{
|
|
2075
|
+
const from = typeAST(ast.from);
|
|
2076
|
+
return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations);
|
|
2077
|
+
}
|
|
2078
|
+
case "Transformation":
|
|
2079
|
+
return typeAST(ast.to);
|
|
2080
|
+
}
|
|
2081
|
+
return ast;
|
|
2082
|
+
};
|
|
2083
|
+
/** @internal */
|
|
2084
|
+
export const whiteListAnnotations = annotationIds => annotated => {
|
|
2085
|
+
let out = undefined;
|
|
2086
|
+
for (const id of annotationIds) {
|
|
2087
|
+
if (Object.prototype.hasOwnProperty.call(annotated.annotations, id)) {
|
|
2088
|
+
if (out === undefined) {
|
|
2089
|
+
out = {};
|
|
2090
|
+
}
|
|
2091
|
+
out[id] = annotated.annotations[id];
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return out;
|
|
2095
|
+
};
|
|
2096
|
+
/** @internal */
|
|
2097
|
+
export const blackListAnnotations = annotationIds => annotated => {
|
|
2098
|
+
const out = {
|
|
2099
|
+
...annotated.annotations
|
|
2100
|
+
};
|
|
2101
|
+
for (const id of annotationIds) {
|
|
2102
|
+
delete out[id];
|
|
2103
|
+
}
|
|
2104
|
+
return out;
|
|
2105
|
+
};
|
|
2106
|
+
// To generate a JSON Schema from a recursive schema, an `identifier` annotation
|
|
2107
|
+
// is required. So, when we calculate the encodedAST, we need to preserve the
|
|
2108
|
+
// annotation in the form of an internal custom annotation that acts as a
|
|
2109
|
+
// surrogate for the identifier, which the JSON Schema compiler can then read.
|
|
2110
|
+
const createJSONIdentifierAnnotation = annotated => Option.match(getJSONIdentifier(annotated), {
|
|
2111
|
+
onNone: () => undefined,
|
|
2112
|
+
onSome: identifier => ({
|
|
2113
|
+
[JSONIdentifierAnnotationId]: identifier
|
|
2114
|
+
})
|
|
2115
|
+
});
|
|
2116
|
+
function changeMap(as, f) {
|
|
2117
|
+
let changed = false;
|
|
2118
|
+
const out = Arr.allocate(as.length);
|
|
2119
|
+
for (let i = 0; i < as.length; i++) {
|
|
2120
|
+
const a = as[i];
|
|
2121
|
+
const fa = f(a);
|
|
2122
|
+
if (fa !== a) {
|
|
2123
|
+
changed = true;
|
|
2124
|
+
}
|
|
2125
|
+
out[i] = fa;
|
|
2126
|
+
}
|
|
2127
|
+
return changed ? out : as;
|
|
2128
|
+
}
|
|
2129
|
+
const encodedAST_ = (ast, isBound) => {
|
|
2130
|
+
switch (ast._tag) {
|
|
2131
|
+
case "Declaration":
|
|
2132
|
+
{
|
|
2133
|
+
const typeParameters = changeMap(ast.typeParameters, ast => encodedAST_(ast, isBound));
|
|
2134
|
+
return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations);
|
|
2135
|
+
}
|
|
2136
|
+
case "TupleType":
|
|
2137
|
+
{
|
|
2138
|
+
const elements = changeMap(ast.elements, e => {
|
|
2139
|
+
const type = encodedAST_(e.type, isBound);
|
|
2140
|
+
return type === e.type ? e : new OptionalType(type, e.isOptional);
|
|
2141
|
+
});
|
|
2142
|
+
const restASTs = getRestASTs(ast.rest);
|
|
2143
|
+
const rest = changeMap(restASTs, ast => encodedAST_(ast, isBound));
|
|
2144
|
+
return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map(ast => new Type(ast)), ast.isReadonly, createJSONIdentifierAnnotation(ast));
|
|
2145
|
+
}
|
|
2146
|
+
case "TypeLiteral":
|
|
2147
|
+
{
|
|
2148
|
+
const propertySignatures = changeMap(ast.propertySignatures, ps => {
|
|
2149
|
+
const type = encodedAST_(ps.type, isBound);
|
|
2150
|
+
return type === ps.type ? ps : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly);
|
|
2151
|
+
});
|
|
2152
|
+
const indexSignatures = changeMap(ast.indexSignatures, is => {
|
|
2153
|
+
const type = encodedAST_(is.type, isBound);
|
|
2154
|
+
return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly);
|
|
2155
|
+
});
|
|
2156
|
+
return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, createJSONIdentifierAnnotation(ast));
|
|
2157
|
+
}
|
|
2158
|
+
case "Union":
|
|
2159
|
+
{
|
|
2160
|
+
const types = changeMap(ast.types, ast => encodedAST_(ast, isBound));
|
|
2161
|
+
return types === ast.types ? ast : Union.make(types, createJSONIdentifierAnnotation(ast));
|
|
2162
|
+
}
|
|
2163
|
+
case "Suspend":
|
|
2164
|
+
return new Suspend(() => encodedAST_(ast.f(), isBound), createJSONIdentifierAnnotation(ast));
|
|
2165
|
+
case "Refinement":
|
|
2166
|
+
{
|
|
2167
|
+
const from = encodedAST_(ast.from, isBound);
|
|
2168
|
+
if (isBound) {
|
|
2169
|
+
if (from === ast.from) {
|
|
2170
|
+
return ast;
|
|
2171
|
+
}
|
|
2172
|
+
if (!isTransformation(ast.from) && hasStableFilter(ast)) {
|
|
2173
|
+
return new Refinement(from, ast.filter);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
return from;
|
|
2177
|
+
}
|
|
2178
|
+
case "Transformation":
|
|
2179
|
+
return encodedAST_(ast.from, isBound);
|
|
2180
|
+
}
|
|
2181
|
+
return ast;
|
|
2182
|
+
};
|
|
2183
|
+
/**
|
|
2184
|
+
* @since 3.10.0
|
|
2185
|
+
*/
|
|
2186
|
+
export const encodedAST = ast => encodedAST_(ast, false);
|
|
2187
|
+
/**
|
|
2188
|
+
* @since 3.10.0
|
|
2189
|
+
*/
|
|
2190
|
+
export const encodedBoundAST = ast => encodedAST_(ast, true);
|
|
2191
|
+
const toJSONAnnotations = annotations => {
|
|
2192
|
+
const out = {};
|
|
2193
|
+
for (const k of Object.getOwnPropertySymbols(annotations)) {
|
|
2194
|
+
out[String(k)] = annotations[k];
|
|
2195
|
+
}
|
|
2196
|
+
return out;
|
|
2197
|
+
};
|
|
2198
|
+
/** @internal */
|
|
2199
|
+
export const getParameterBase = ast => {
|
|
2200
|
+
switch (ast._tag) {
|
|
2201
|
+
case "StringKeyword":
|
|
2202
|
+
case "SymbolKeyword":
|
|
2203
|
+
case "TemplateLiteral":
|
|
2204
|
+
return ast;
|
|
2205
|
+
case "Refinement":
|
|
2206
|
+
return getParameterBase(ast.from);
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
const equalsTemplateLiteralSpan = /*#__PURE__*/Arr.getEquivalence((self, that) => self.type._tag === that.type._tag && self.literal === that.literal);
|
|
2210
|
+
const equalsEnums = /*#__PURE__*/Arr.getEquivalence((self, that) => that[0] === self[0] && that[1] === self[1]);
|
|
2211
|
+
const equals = (self, that) => {
|
|
2212
|
+
switch (self._tag) {
|
|
2213
|
+
case "Literal":
|
|
2214
|
+
return isLiteral(that) && that.literal === self.literal;
|
|
2215
|
+
case "UniqueSymbol":
|
|
2216
|
+
return isUniqueSymbol(that) && that.symbol === self.symbol;
|
|
2217
|
+
case "UndefinedKeyword":
|
|
2218
|
+
case "VoidKeyword":
|
|
2219
|
+
case "NeverKeyword":
|
|
2220
|
+
case "UnknownKeyword":
|
|
2221
|
+
case "AnyKeyword":
|
|
2222
|
+
case "StringKeyword":
|
|
2223
|
+
case "NumberKeyword":
|
|
2224
|
+
case "BooleanKeyword":
|
|
2225
|
+
case "BigIntKeyword":
|
|
2226
|
+
case "SymbolKeyword":
|
|
2227
|
+
case "ObjectKeyword":
|
|
2228
|
+
return that._tag === self._tag;
|
|
2229
|
+
case "TemplateLiteral":
|
|
2230
|
+
return isTemplateLiteral(that) && that.head === self.head && equalsTemplateLiteralSpan(that.spans, self.spans);
|
|
2231
|
+
case "Enums":
|
|
2232
|
+
return isEnums(that) && equalsEnums(that.enums, self.enums);
|
|
2233
|
+
case "Refinement":
|
|
2234
|
+
case "TupleType":
|
|
2235
|
+
case "TypeLiteral":
|
|
2236
|
+
case "Union":
|
|
2237
|
+
case "Suspend":
|
|
2238
|
+
case "Transformation":
|
|
2239
|
+
case "Declaration":
|
|
2240
|
+
return self === that;
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
const intersection = /*#__PURE__*/Arr.intersectionWith(equals);
|
|
2244
|
+
const _keyof = ast => {
|
|
2245
|
+
switch (ast._tag) {
|
|
2246
|
+
case "Declaration":
|
|
2247
|
+
{
|
|
2248
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
2249
|
+
if (Option.isSome(annotation)) {
|
|
2250
|
+
return _keyof(annotation.value);
|
|
2251
|
+
}
|
|
2252
|
+
break;
|
|
2253
|
+
}
|
|
2254
|
+
case "TypeLiteral":
|
|
2255
|
+
return ast.propertySignatures.map(p => Predicate.isSymbol(p.name) ? new UniqueSymbol(p.name) : new Literal(p.name)).concat(ast.indexSignatures.map(is => getParameterBase(is.parameter)));
|
|
2256
|
+
case "Suspend":
|
|
2257
|
+
return _keyof(ast.f());
|
|
2258
|
+
case "Union":
|
|
2259
|
+
return ast.types.slice(1).reduce((out, ast) => intersection(out, _keyof(ast)), _keyof(ast.types[0]));
|
|
2260
|
+
case "Transformation":
|
|
2261
|
+
return _keyof(ast.to);
|
|
2262
|
+
}
|
|
2263
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2264
|
+
};
|
|
2265
|
+
/** @internal */
|
|
2266
|
+
export const compose = (ab, cd) => new Transformation(ab, cd, composeTransformation);
|
|
2267
|
+
/** @internal */
|
|
2268
|
+
export const rename = (ast, mapping) => {
|
|
2269
|
+
switch (ast._tag) {
|
|
2270
|
+
case "TypeLiteral":
|
|
2271
|
+
{
|
|
2272
|
+
const propertySignatureTransformations = [];
|
|
2273
|
+
for (const key of util_.ownKeys(mapping)) {
|
|
2274
|
+
const name = mapping[key];
|
|
2275
|
+
if (name !== undefined) {
|
|
2276
|
+
propertySignatureTransformations.push(new PropertySignatureTransformation(key, name, identity, identity));
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
if (propertySignatureTransformations.length === 0) {
|
|
2280
|
+
return ast;
|
|
2281
|
+
}
|
|
2282
|
+
return new Transformation(ast, new TypeLiteral(ast.propertySignatures.map(ps => {
|
|
2283
|
+
const name = mapping[ps.name];
|
|
2284
|
+
return new PropertySignature(name === undefined ? ps.name : name, typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations);
|
|
2285
|
+
}), ast.indexSignatures), new TypeLiteralTransformation(propertySignatureTransformations));
|
|
2286
|
+
}
|
|
2287
|
+
case "Union":
|
|
2288
|
+
return Union.make(ast.types.map(ast => rename(ast, mapping)));
|
|
2289
|
+
case "Suspend":
|
|
2290
|
+
return new Suspend(() => rename(ast.f(), mapping));
|
|
2291
|
+
case "Transformation":
|
|
2292
|
+
return compose(ast, rename(typeAST(ast), mapping));
|
|
2293
|
+
}
|
|
2294
|
+
throw new Error(errors_.getASTUnsupportedRenameSchema(ast));
|
|
2295
|
+
};
|
|
2296
|
+
const formatKeyword = ast => Option.getOrElse(getExpected(ast), () => ast._tag);
|
|
2297
|
+
const getExpected = ast => {
|
|
2298
|
+
return getIdentifierAnnotation(ast).pipe(Option.orElse(() => getTitleAnnotation(ast)), Option.orElse(() => getDescriptionAnnotation(ast)));
|
|
2299
|
+
};
|
|
2300
|
+
//# sourceMappingURL=SchemaAST.js.map
|