effect 3.9.2 → 3.10.0

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.
Files changed (202) hide show
  1. package/Arbitrary/package.json +6 -0
  2. package/FastCheck/package.json +6 -0
  3. package/JSONSchema/package.json +6 -0
  4. package/ParseResult/package.json +6 -0
  5. package/Pretty/package.json +6 -0
  6. package/Schema/package.json +6 -0
  7. package/SchemaAST/package.json +6 -0
  8. package/TSubscriptionRef/package.json +6 -0
  9. package/dist/cjs/Arbitrary.js +490 -0
  10. package/dist/cjs/Arbitrary.js.map +1 -0
  11. package/dist/cjs/Effect.js +247 -16
  12. package/dist/cjs/Effect.js.map +1 -1
  13. package/dist/cjs/FastCheck.js +17 -0
  14. package/dist/cjs/FastCheck.js.map +1 -0
  15. package/dist/cjs/Inspectable.js +43 -3
  16. package/dist/cjs/Inspectable.js.map +1 -1
  17. package/dist/cjs/JSONSchema.js +418 -0
  18. package/dist/cjs/JSONSchema.js.map +1 -0
  19. package/dist/cjs/ParseResult.js +1539 -0
  20. package/dist/cjs/ParseResult.js.map +1 -0
  21. package/dist/cjs/Predicate.js +3 -1
  22. package/dist/cjs/Predicate.js.map +1 -1
  23. package/dist/cjs/Pretty.js +183 -0
  24. package/dist/cjs/Pretty.js.map +1 -0
  25. package/dist/cjs/Schema.js +5529 -0
  26. package/dist/cjs/Schema.js.map +1 -0
  27. package/dist/cjs/SchemaAST.js +2365 -0
  28. package/dist/cjs/SchemaAST.js.map +1 -0
  29. package/dist/cjs/Stream.js +17 -3
  30. package/dist/cjs/Stream.js.map +1 -1
  31. package/dist/cjs/TPubSub.js +9 -1
  32. package/dist/cjs/TPubSub.js.map +1 -1
  33. package/dist/cjs/TQueue.js.map +1 -1
  34. package/dist/cjs/TRef.js.map +1 -1
  35. package/dist/cjs/TSubscriptionRef.js +96 -0
  36. package/dist/cjs/TSubscriptionRef.js.map +1 -0
  37. package/dist/cjs/index.js +18 -2
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/internal/cause.js +2 -2
  40. package/dist/cjs/internal/cause.js.map +1 -1
  41. package/dist/cjs/internal/core.js +4 -4
  42. package/dist/cjs/internal/core.js.map +1 -1
  43. package/dist/cjs/internal/fiberRuntime.js +14 -12
  44. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  45. package/dist/cjs/internal/logger.js +7 -6
  46. package/dist/cjs/internal/logger.js.map +1 -1
  47. package/dist/cjs/internal/redacted.js +4 -0
  48. package/dist/cjs/internal/redacted.js.map +1 -1
  49. package/dist/cjs/internal/schema/errors.js +116 -0
  50. package/dist/cjs/internal/schema/errors.js.map +1 -0
  51. package/dist/cjs/internal/schema/filters.js +41 -0
  52. package/dist/cjs/internal/schema/filters.js.map +1 -0
  53. package/dist/cjs/internal/schema/util.js +96 -0
  54. package/dist/cjs/internal/schema/util.js.map +1 -0
  55. package/dist/cjs/internal/stm/core.js +2 -3
  56. package/dist/cjs/internal/stm/core.js.map +1 -1
  57. package/dist/cjs/internal/stm/tPubSub.js.map +1 -1
  58. package/dist/cjs/internal/stm/tQueue.js +1 -2
  59. package/dist/cjs/internal/stm/tQueue.js.map +1 -1
  60. package/dist/cjs/internal/stm/tRef.js +6 -2
  61. package/dist/cjs/internal/stm/tRef.js.map +1 -1
  62. package/dist/cjs/internal/stm/tSubscriptionRef.js +178 -0
  63. package/dist/cjs/internal/stm/tSubscriptionRef.js.map +1 -0
  64. package/dist/cjs/internal/stream.js +36 -16
  65. package/dist/cjs/internal/stream.js.map +1 -1
  66. package/dist/cjs/internal/version.js +1 -1
  67. package/dist/cjs/internal/version.js.map +1 -1
  68. package/dist/dts/Arbitrary.d.ts +45 -0
  69. package/dist/dts/Arbitrary.d.ts.map +1 -0
  70. package/dist/dts/Effect.d.ts +298 -30
  71. package/dist/dts/Effect.d.ts.map +1 -1
  72. package/dist/dts/FastCheck.d.ts +9 -0
  73. package/dist/dts/FastCheck.d.ts.map +1 -0
  74. package/dist/dts/Inspectable.d.ts +28 -0
  75. package/dist/dts/Inspectable.d.ts.map +1 -1
  76. package/dist/dts/JSONSchema.d.ts +181 -0
  77. package/dist/dts/JSONSchema.d.ts.map +1 -0
  78. package/dist/dts/ParseResult.d.ts +551 -0
  79. package/dist/dts/ParseResult.d.ts.map +1 -0
  80. package/dist/dts/Predicate.d.ts.map +1 -1
  81. package/dist/dts/Pretty.d.ts +26 -0
  82. package/dist/dts/Pretty.d.ts.map +1 -0
  83. package/dist/dts/Schema.d.ts +4562 -0
  84. package/dist/dts/Schema.d.ts.map +1 -0
  85. package/dist/dts/SchemaAST.d.ts +1321 -0
  86. package/dist/dts/SchemaAST.d.ts.map +1 -0
  87. package/dist/dts/Stream.d.ts +67 -2
  88. package/dist/dts/Stream.d.ts.map +1 -1
  89. package/dist/dts/TPubSub.d.ts +8 -0
  90. package/dist/dts/TPubSub.d.ts.map +1 -1
  91. package/dist/dts/TQueue.d.ts +7 -7
  92. package/dist/dts/TQueue.d.ts.map +1 -1
  93. package/dist/dts/TRef.d.ts +2 -1
  94. package/dist/dts/TRef.d.ts.map +1 -1
  95. package/dist/dts/TSubscriptionRef.d.ts +251 -0
  96. package/dist/dts/TSubscriptionRef.d.ts.map +1 -0
  97. package/dist/dts/index.d.ts +32 -0
  98. package/dist/dts/index.d.ts.map +1 -1
  99. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  100. package/dist/dts/internal/schema/errors.d.ts +2 -0
  101. package/dist/dts/internal/schema/errors.d.ts.map +1 -0
  102. package/dist/dts/internal/schema/filters.d.ts +2 -0
  103. package/dist/dts/internal/schema/filters.d.ts.map +1 -0
  104. package/dist/dts/internal/schema/util.d.ts +2 -0
  105. package/dist/dts/internal/schema/util.d.ts.map +1 -0
  106. package/dist/dts/internal/stm/tRef.d.ts +3 -1
  107. package/dist/dts/internal/stm/tRef.d.ts.map +1 -1
  108. package/dist/dts/internal/stm/tSubscriptionRef.d.ts +2 -0
  109. package/dist/dts/internal/stm/tSubscriptionRef.d.ts.map +1 -0
  110. package/dist/dts/internal/stream.d.ts.map +1 -1
  111. package/dist/esm/Arbitrary.js +472 -0
  112. package/dist/esm/Arbitrary.js.map +1 -0
  113. package/dist/esm/Effect.js +256 -18
  114. package/dist/esm/Effect.js.map +1 -1
  115. package/dist/esm/FastCheck.js +9 -0
  116. package/dist/esm/FastCheck.js.map +1 -0
  117. package/dist/esm/Inspectable.js +39 -2
  118. package/dist/esm/Inspectable.js.map +1 -1
  119. package/dist/esm/JSONSchema.js +408 -0
  120. package/dist/esm/JSONSchema.js.map +1 -0
  121. package/dist/esm/ParseResult.js +1503 -0
  122. package/dist/esm/ParseResult.js.map +1 -0
  123. package/dist/esm/Predicate.js +2 -1
  124. package/dist/esm/Predicate.js.map +1 -1
  125. package/dist/esm/Pretty.js +173 -0
  126. package/dist/esm/Pretty.js.map +1 -0
  127. package/dist/esm/Schema.js +5328 -0
  128. package/dist/esm/Schema.js.map +1 -0
  129. package/dist/esm/SchemaAST.js +2300 -0
  130. package/dist/esm/SchemaAST.js.map +1 -0
  131. package/dist/esm/Stream.js +14 -0
  132. package/dist/esm/Stream.js.map +1 -1
  133. package/dist/esm/TPubSub.js +8 -0
  134. package/dist/esm/TPubSub.js.map +1 -1
  135. package/dist/esm/TQueue.js.map +1 -1
  136. package/dist/esm/TRef.js.map +1 -1
  137. package/dist/esm/TSubscriptionRef.js +87 -0
  138. package/dist/esm/TSubscriptionRef.js.map +1 -0
  139. package/dist/esm/index.js +32 -0
  140. package/dist/esm/index.js.map +1 -1
  141. package/dist/esm/internal/cause.js +3 -3
  142. package/dist/esm/internal/cause.js.map +1 -1
  143. package/dist/esm/internal/core.js +4 -4
  144. package/dist/esm/internal/core.js.map +1 -1
  145. package/dist/esm/internal/fiberRuntime.js +14 -12
  146. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  147. package/dist/esm/internal/logger.js +7 -6
  148. package/dist/esm/internal/logger.js.map +1 -1
  149. package/dist/esm/internal/redacted.js +4 -0
  150. package/dist/esm/internal/redacted.js.map +1 -1
  151. package/dist/esm/internal/schema/errors.js +87 -0
  152. package/dist/esm/internal/schema/errors.js.map +1 -0
  153. package/dist/esm/internal/schema/filters.js +35 -0
  154. package/dist/esm/internal/schema/filters.js.map +1 -0
  155. package/dist/esm/internal/schema/util.js +78 -0
  156. package/dist/esm/internal/schema/util.js.map +1 -0
  157. package/dist/esm/internal/stm/core.js +1 -2
  158. package/dist/esm/internal/stm/core.js.map +1 -1
  159. package/dist/esm/internal/stm/tPubSub.js.map +1 -1
  160. package/dist/esm/internal/stm/tQueue.js +1 -2
  161. package/dist/esm/internal/stm/tQueue.js.map +1 -1
  162. package/dist/esm/internal/stm/tRef.js +5 -1
  163. package/dist/esm/internal/stm/tRef.js.map +1 -1
  164. package/dist/esm/internal/stm/tSubscriptionRef.js +166 -0
  165. package/dist/esm/internal/stm/tSubscriptionRef.js.map +1 -0
  166. package/dist/esm/internal/stream.js +33 -15
  167. package/dist/esm/internal/stream.js.map +1 -1
  168. package/dist/esm/internal/version.js +1 -1
  169. package/dist/esm/internal/version.js.map +1 -1
  170. package/package.json +68 -1
  171. package/src/Arbitrary.ts +563 -0
  172. package/src/Effect.ts +302 -31
  173. package/src/FastCheck.ts +9 -0
  174. package/src/Inspectable.ts +56 -2
  175. package/src/JSONSchema.ts +601 -0
  176. package/src/ParseResult.ts +2027 -0
  177. package/src/Predicate.ts +3 -1
  178. package/src/Pretty.ts +204 -0
  179. package/src/Schema.ts +10388 -0
  180. package/src/SchemaAST.ts +2827 -0
  181. package/src/Stream.ts +77 -9
  182. package/src/TPubSub.ts +9 -0
  183. package/src/TQueue.ts +7 -7
  184. package/src/TRef.ts +2 -1
  185. package/src/TSubscriptionRef.ts +284 -0
  186. package/src/index.ts +40 -0
  187. package/src/internal/cause.ts +3 -3
  188. package/src/internal/core-effect.ts +2 -2
  189. package/src/internal/core.ts +4 -4
  190. package/src/internal/fiberRuntime.ts +14 -12
  191. package/src/internal/logger.ts +7 -6
  192. package/src/internal/redacted.ts +4 -0
  193. package/src/internal/schema/errors.ts +189 -0
  194. package/src/internal/schema/filters.ts +86 -0
  195. package/src/internal/schema/util.ts +113 -0
  196. package/src/internal/stm/core.ts +1 -2
  197. package/src/internal/stm/tPubSub.ts +1 -0
  198. package/src/internal/stm/tQueue.ts +2 -2
  199. package/src/internal/stm/tRef.ts +7 -2
  200. package/src/internal/stm/tSubscriptionRef.ts +286 -0
  201. package/src/internal/stream.ts +97 -20
  202. package/src/internal/version.ts +1 -1
@@ -0,0 +1,1539 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateSync = exports.validatePromise = exports.validateOption = exports.validateEither = exports.validate = exports.try = exports.succeed = exports.parseError = exports.orElse = exports.mergeInternalOptions = exports.mapError = exports.mapBoth = exports.map = exports.isParseError = exports.isComposite = exports.is = exports.getSearchTree = exports.getLiterals = exports.getFinalTransformation = exports.fromOption = exports.flatMap = exports.fail = exports.encodeUnknownSync = exports.encodeUnknownPromise = exports.encodeUnknownOption = exports.encodeUnknownEither = exports.encodeUnknown = exports.encodeSync = exports.encodePromise = exports.encodeOption = exports.encodeEither = exports.encode = exports.eitherOrUndefined = exports.decodeUnknownSync = exports.decodeUnknownPromise = exports.decodeUnknownOption = exports.decodeUnknownEither = exports.decodeUnknown = exports.decodeSync = exports.decodePromise = exports.decodeOption = exports.decodeEither = exports.decode = exports.asserts = exports.Unexpected = exports.Type = exports.TreeFormatter = exports.Transformation = exports.Refinement = exports.Pointer = exports.ParseErrorTypeId = exports.ParseError = exports.Missing = exports.Forbidden = exports.Composite = exports.ArrayFormatter = void 0;
7
+ var array_ = _interopRequireWildcard(require("./Array.js"));
8
+ var _Data = require("./Data.js");
9
+ var Effect = _interopRequireWildcard(require("./Effect.js"));
10
+ var Either = _interopRequireWildcard(require("./Either.js"));
11
+ var _Function = require("./Function.js");
12
+ var _GlobalValue = require("./GlobalValue.js");
13
+ var Inspectable = _interopRequireWildcard(require("./Inspectable.js"));
14
+ var util_ = _interopRequireWildcard(require("./internal/schema/util.js"));
15
+ var Option = _interopRequireWildcard(require("./Option.js"));
16
+ var Predicate = _interopRequireWildcard(require("./Predicate.js"));
17
+ var AST = _interopRequireWildcard(require("./SchemaAST.js"));
18
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
+ /**
21
+ * @since 3.10.0
22
+ */
23
+
24
+ /**
25
+ * @category model
26
+ * @since 3.10.0
27
+ */
28
+ class Pointer {
29
+ path;
30
+ actual;
31
+ issue;
32
+ /**
33
+ * @since 3.10.0
34
+ */
35
+ _tag = "Pointer";
36
+ constructor(path, actual, issue) {
37
+ this.path = path;
38
+ this.actual = actual;
39
+ this.issue = issue;
40
+ }
41
+ }
42
+ /**
43
+ * Error that occurs when an unexpected key or index is present.
44
+ *
45
+ * @category model
46
+ * @since 3.10.0
47
+ */
48
+ exports.Pointer = Pointer;
49
+ class Unexpected {
50
+ actual;
51
+ message;
52
+ /**
53
+ * @since 3.10.0
54
+ */
55
+ _tag = "Unexpected";
56
+ constructor(actual,
57
+ /**
58
+ * @since 3.10.0
59
+ */
60
+ message) {
61
+ this.actual = actual;
62
+ this.message = message;
63
+ }
64
+ }
65
+ /**
66
+ * Error that occurs when a required key or index is missing.
67
+ *
68
+ * @category model
69
+ * @since 3.10.0
70
+ */
71
+ exports.Unexpected = Unexpected;
72
+ class Missing {
73
+ ast;
74
+ message;
75
+ /**
76
+ * @since 3.10.0
77
+ */
78
+ _tag = "Missing";
79
+ /**
80
+ * @since 3.10.0
81
+ */
82
+ actual = undefined;
83
+ constructor(
84
+ /**
85
+ * @since 3.10.0
86
+ */
87
+ ast,
88
+ /**
89
+ * @since 3.10.0
90
+ */
91
+ message) {
92
+ this.ast = ast;
93
+ this.message = message;
94
+ }
95
+ }
96
+ /**
97
+ * Error that contains multiple issues.
98
+ *
99
+ * @category model
100
+ * @since 3.10.0
101
+ */
102
+ exports.Missing = Missing;
103
+ class Composite {
104
+ ast;
105
+ actual;
106
+ issues;
107
+ output;
108
+ /**
109
+ * @since 3.10.0
110
+ */
111
+ _tag = "Composite";
112
+ constructor(ast, actual, issues, output) {
113
+ this.ast = ast;
114
+ this.actual = actual;
115
+ this.issues = issues;
116
+ this.output = output;
117
+ }
118
+ }
119
+ /**
120
+ * Error that occurs when a refinement has an error.
121
+ *
122
+ * @category model
123
+ * @since 3.10.0
124
+ */
125
+ exports.Composite = Composite;
126
+ class Refinement {
127
+ ast;
128
+ actual;
129
+ kind;
130
+ issue;
131
+ /**
132
+ * @since 3.10.0
133
+ */
134
+ _tag = "Refinement";
135
+ constructor(ast, actual, kind, issue) {
136
+ this.ast = ast;
137
+ this.actual = actual;
138
+ this.kind = kind;
139
+ this.issue = issue;
140
+ }
141
+ }
142
+ /**
143
+ * Error that occurs when a transformation has an error.
144
+ *
145
+ * @category model
146
+ * @since 3.10.0
147
+ */
148
+ exports.Refinement = Refinement;
149
+ class Transformation {
150
+ ast;
151
+ actual;
152
+ kind;
153
+ issue;
154
+ /**
155
+ * @since 3.10.0
156
+ */
157
+ _tag = "Transformation";
158
+ constructor(ast, actual, kind, issue) {
159
+ this.ast = ast;
160
+ this.actual = actual;
161
+ this.kind = kind;
162
+ this.issue = issue;
163
+ }
164
+ }
165
+ /**
166
+ * The `Type` variant of the `ParseIssue` type represents an error that occurs when the `actual` value is not of the expected type.
167
+ * The `ast` field specifies the expected type, and the `actual` field contains the value that caused the error.
168
+ *
169
+ * @category model
170
+ * @since 3.10.0
171
+ */
172
+ exports.Transformation = Transformation;
173
+ class Type {
174
+ ast;
175
+ actual;
176
+ message;
177
+ /**
178
+ * @since 3.10.0
179
+ */
180
+ _tag = "Type";
181
+ constructor(ast, actual, message) {
182
+ this.ast = ast;
183
+ this.actual = actual;
184
+ this.message = message;
185
+ }
186
+ }
187
+ /**
188
+ * The `Forbidden` variant of the `ParseIssue` type represents a forbidden operation, such as when encountering an Effect that is not allowed to execute (e.g., using `runSync`).
189
+ *
190
+ * @category model
191
+ * @since 3.10.0
192
+ */
193
+ exports.Type = Type;
194
+ class Forbidden {
195
+ ast;
196
+ actual;
197
+ message;
198
+ /**
199
+ * @since 3.10.0
200
+ */
201
+ _tag = "Forbidden";
202
+ constructor(ast, actual, message) {
203
+ this.ast = ast;
204
+ this.actual = actual;
205
+ this.message = message;
206
+ }
207
+ }
208
+ /**
209
+ * @category type id
210
+ * @since 3.10.0
211
+ */
212
+ exports.Forbidden = Forbidden;
213
+ const ParseErrorTypeId = exports.ParseErrorTypeId = /*#__PURE__*/Symbol.for("effect/Schema/ParseErrorTypeId");
214
+ /**
215
+ * @since 3.10.0
216
+ */
217
+ const isParseError = u => Predicate.hasProperty(u, ParseErrorTypeId);
218
+ /**
219
+ * @since 3.10.0
220
+ */
221
+ exports.isParseError = isParseError;
222
+ class ParseError extends /*#__PURE__*/(0, _Data.TaggedError)("ParseError") {
223
+ /**
224
+ * @since 3.10.0
225
+ */
226
+ [ParseErrorTypeId] = ParseErrorTypeId;
227
+ get message() {
228
+ return this.toString();
229
+ }
230
+ /**
231
+ * @since 3.10.0
232
+ */
233
+ toString() {
234
+ return TreeFormatter.formatIssueSync(this.issue);
235
+ }
236
+ /**
237
+ * @since 3.10.0
238
+ */
239
+ toJSON() {
240
+ return {
241
+ _id: "ParseError",
242
+ message: this.toString()
243
+ };
244
+ }
245
+ /**
246
+ * @since 3.10.0
247
+ */
248
+ [Inspectable.NodeInspectSymbol]() {
249
+ return this.toJSON();
250
+ }
251
+ }
252
+ /**
253
+ * @category constructors
254
+ * @since 3.10.0
255
+ */
256
+ exports.ParseError = ParseError;
257
+ const parseError = issue => new ParseError({
258
+ issue
259
+ });
260
+ /**
261
+ * @category constructors
262
+ * @since 3.10.0
263
+ */
264
+ exports.parseError = parseError;
265
+ const succeed = exports.succeed = Either.right;
266
+ /**
267
+ * @category constructors
268
+ * @since 3.10.0
269
+ */
270
+ const fail = exports.fail = Either.left;
271
+ const _try = exports.try = Either.try;
272
+ /**
273
+ * @category constructors
274
+ * @since 3.10.0
275
+ */
276
+ const fromOption = exports.fromOption = Either.fromOption;
277
+ /**
278
+ * @category optimisation
279
+ * @since 3.10.0
280
+ */
281
+ const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
282
+ const s = self;
283
+ if (s["_tag"] === "Left") {
284
+ return s;
285
+ }
286
+ if (s["_tag"] === "Right") {
287
+ return f(s.right);
288
+ }
289
+ return Effect.flatMap(self, f);
290
+ });
291
+ /**
292
+ * @category optimisation
293
+ * @since 3.10.0
294
+ */
295
+ const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
296
+ const s = self;
297
+ if (s["_tag"] === "Left") {
298
+ return s;
299
+ }
300
+ if (s["_tag"] === "Right") {
301
+ return Either.right(f(s.right));
302
+ }
303
+ return Effect.map(self, f);
304
+ });
305
+ /**
306
+ * @category optimisation
307
+ * @since 3.10.0
308
+ */
309
+ const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
310
+ const s = self;
311
+ if (s["_tag"] === "Left") {
312
+ return Either.left(f(s.left));
313
+ }
314
+ if (s["_tag"] === "Right") {
315
+ return s;
316
+ }
317
+ return Effect.mapError(self, f);
318
+ });
319
+ /**
320
+ * @category optimisation
321
+ * @since 3.10.0
322
+ */
323
+ const eitherOrUndefined = self => {
324
+ const s = self;
325
+ if (s["_tag"] === "Left" || s["_tag"] === "Right") {
326
+ return s;
327
+ }
328
+ };
329
+ /**
330
+ * @category optimisation
331
+ * @since 3.10.0
332
+ */
333
+ exports.eitherOrUndefined = eitherOrUndefined;
334
+ const mapBoth = exports.mapBoth = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => {
335
+ const s = self;
336
+ if (s["_tag"] === "Left") {
337
+ return Either.left(options.onFailure(s.left));
338
+ }
339
+ if (s["_tag"] === "Right") {
340
+ return Either.right(options.onSuccess(s.right));
341
+ }
342
+ return Effect.mapBoth(self, options);
343
+ });
344
+ /**
345
+ * @category optimisation
346
+ * @since 3.10.0
347
+ */
348
+ const orElse = exports.orElse = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
349
+ const s = self;
350
+ if (s["_tag"] === "Left") {
351
+ return f(s.left);
352
+ }
353
+ if (s["_tag"] === "Right") {
354
+ return s;
355
+ }
356
+ return Effect.catchAll(self, f);
357
+ });
358
+ /** @internal */
359
+ const mergeInternalOptions = (options, overrideOptions) => {
360
+ if (overrideOptions === undefined || Predicate.isNumber(overrideOptions)) {
361
+ return options;
362
+ }
363
+ if (options === undefined) {
364
+ return overrideOptions;
365
+ }
366
+ return {
367
+ ...options,
368
+ ...overrideOptions
369
+ };
370
+ };
371
+ exports.mergeInternalOptions = mergeInternalOptions;
372
+ const getEither = (ast, isDecoding, options) => {
373
+ const parser = goMemo(ast, isDecoding);
374
+ return (u, overrideOptions) => parser(u, mergeInternalOptions(options, overrideOptions));
375
+ };
376
+ const getSync = (ast, isDecoding, options) => {
377
+ const parser = getEither(ast, isDecoding, options);
378
+ return (input, overrideOptions) => Either.getOrThrowWith(parser(input, overrideOptions), parseError);
379
+ };
380
+ const getOption = (ast, isDecoding, options) => {
381
+ const parser = getEither(ast, isDecoding, options);
382
+ return (input, overrideOptions) => Option.getRight(parser(input, overrideOptions));
383
+ };
384
+ const getEffect = (ast, isDecoding, options) => {
385
+ const parser = goMemo(ast, isDecoding);
386
+ return (input, overrideOptions) => parser(input, {
387
+ ...mergeInternalOptions(options, overrideOptions),
388
+ isEffectAllowed: true
389
+ });
390
+ };
391
+ /**
392
+ * @throws `ParseError`
393
+ * @category decoding
394
+ * @since 3.10.0
395
+ */
396
+ const decodeUnknownSync = (schema, options) => getSync(schema.ast, true, options);
397
+ /**
398
+ * @category decoding
399
+ * @since 3.10.0
400
+ */
401
+ exports.decodeUnknownSync = decodeUnknownSync;
402
+ const decodeUnknownOption = (schema, options) => getOption(schema.ast, true, options);
403
+ /**
404
+ * @category decoding
405
+ * @since 3.10.0
406
+ */
407
+ exports.decodeUnknownOption = decodeUnknownOption;
408
+ const decodeUnknownEither = (schema, options) => getEither(schema.ast, true, options);
409
+ /**
410
+ * @category decoding
411
+ * @since 3.10.0
412
+ */
413
+ exports.decodeUnknownEither = decodeUnknownEither;
414
+ const decodeUnknownPromise = (schema, options) => {
415
+ const parser = decodeUnknown(schema, options);
416
+ return (u, overrideOptions) => Effect.runPromise(parser(u, overrideOptions));
417
+ };
418
+ /**
419
+ * @category decoding
420
+ * @since 3.10.0
421
+ */
422
+ exports.decodeUnknownPromise = decodeUnknownPromise;
423
+ const decodeUnknown = (schema, options) => getEffect(schema.ast, true, options);
424
+ /**
425
+ * @throws `ParseError`
426
+ * @category encoding
427
+ * @since 3.10.0
428
+ */
429
+ exports.decodeUnknown = decodeUnknown;
430
+ const encodeUnknownSync = (schema, options) => getSync(schema.ast, false, options);
431
+ /**
432
+ * @category encoding
433
+ * @since 3.10.0
434
+ */
435
+ exports.encodeUnknownSync = encodeUnknownSync;
436
+ const encodeUnknownOption = (schema, options) => getOption(schema.ast, false, options);
437
+ /**
438
+ * @category encoding
439
+ * @since 3.10.0
440
+ */
441
+ exports.encodeUnknownOption = encodeUnknownOption;
442
+ const encodeUnknownEither = (schema, options) => getEither(schema.ast, false, options);
443
+ /**
444
+ * @category encoding
445
+ * @since 3.10.0
446
+ */
447
+ exports.encodeUnknownEither = encodeUnknownEither;
448
+ const encodeUnknownPromise = (schema, options) => {
449
+ const parser = encodeUnknown(schema, options);
450
+ return (u, overrideOptions) => Effect.runPromise(parser(u, overrideOptions));
451
+ };
452
+ /**
453
+ * @category encoding
454
+ * @since 3.10.0
455
+ */
456
+ exports.encodeUnknownPromise = encodeUnknownPromise;
457
+ const encodeUnknown = (schema, options) => getEffect(schema.ast, false, options);
458
+ /**
459
+ * @category decoding
460
+ * @since 3.10.0
461
+ */
462
+ exports.encodeUnknown = encodeUnknown;
463
+ const decodeSync = exports.decodeSync = decodeUnknownSync;
464
+ /**
465
+ * @category decoding
466
+ * @since 3.10.0
467
+ */
468
+ const decodeOption = exports.decodeOption = decodeUnknownOption;
469
+ /**
470
+ * @category decoding
471
+ * @since 3.10.0
472
+ */
473
+ const decodeEither = exports.decodeEither = decodeUnknownEither;
474
+ /**
475
+ * @category decoding
476
+ * @since 3.10.0
477
+ */
478
+ const decodePromise = exports.decodePromise = decodeUnknownPromise;
479
+ /**
480
+ * @category decoding
481
+ * @since 3.10.0
482
+ */
483
+ const decode = exports.decode = decodeUnknown;
484
+ /**
485
+ * @throws `ParseError`
486
+ * @category validation
487
+ * @since 3.10.0
488
+ */
489
+ const validateSync = (schema, options) => getSync(AST.typeAST(schema.ast), true, options);
490
+ /**
491
+ * @category validation
492
+ * @since 3.10.0
493
+ */
494
+ exports.validateSync = validateSync;
495
+ const validateOption = (schema, options) => getOption(AST.typeAST(schema.ast), true, options);
496
+ /**
497
+ * @category validation
498
+ * @since 3.10.0
499
+ */
500
+ exports.validateOption = validateOption;
501
+ const validateEither = (schema, options) => getEither(AST.typeAST(schema.ast), true, options);
502
+ /**
503
+ * @category validation
504
+ * @since 3.10.0
505
+ */
506
+ exports.validateEither = validateEither;
507
+ const validatePromise = (schema, options) => {
508
+ const parser = validate(schema, options);
509
+ return (u, overrideOptions) => Effect.runPromise(parser(u, overrideOptions));
510
+ };
511
+ /**
512
+ * @category validation
513
+ * @since 3.10.0
514
+ */
515
+ exports.validatePromise = validatePromise;
516
+ const validate = (schema, options) => getEffect(AST.typeAST(schema.ast), true, options);
517
+ /**
518
+ * By default the option `exact` is set to `true`.
519
+ *
520
+ * @category validation
521
+ * @since 3.10.0
522
+ */
523
+ exports.validate = validate;
524
+ const is = (schema, options) => {
525
+ const parser = goMemo(AST.typeAST(schema.ast), true);
526
+ return (u, overrideOptions) => Either.isRight(parser(u, {
527
+ exact: true,
528
+ ...mergeInternalOptions(options, overrideOptions)
529
+ }));
530
+ };
531
+ /**
532
+ * By default the option `exact` is set to `true`.
533
+ *
534
+ * @throws `ParseError`
535
+ * @category validation
536
+ * @since 3.10.0
537
+ */
538
+ exports.is = is;
539
+ const asserts = (schema, options) => {
540
+ const parser = goMemo(AST.typeAST(schema.ast), true);
541
+ return (u, overrideOptions) => {
542
+ const result = parser(u, {
543
+ exact: true,
544
+ ...mergeInternalOptions(options, overrideOptions)
545
+ });
546
+ if (Either.isLeft(result)) {
547
+ throw parseError(result.left);
548
+ }
549
+ };
550
+ };
551
+ /**
552
+ * @category encoding
553
+ * @since 3.10.0
554
+ */
555
+ exports.asserts = asserts;
556
+ const encodeSync = exports.encodeSync = encodeUnknownSync;
557
+ /**
558
+ * @category encoding
559
+ * @since 3.10.0
560
+ */
561
+ const encodeOption = exports.encodeOption = encodeUnknownOption;
562
+ /**
563
+ * @category encoding
564
+ * @since 3.10.0
565
+ */
566
+ const encodeEither = exports.encodeEither = encodeUnknownEither;
567
+ /**
568
+ * @category encoding
569
+ * @since 3.10.0
570
+ */
571
+ const encodePromise = exports.encodePromise = encodeUnknownPromise;
572
+ /**
573
+ * @category encoding
574
+ * @since 3.10.0
575
+ */
576
+ const encode = exports.encode = encodeUnknown;
577
+ const decodeMemoMap = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/Schema/Parser/decodeMemoMap"), () => new WeakMap());
578
+ const encodeMemoMap = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/Schema/Parser/encodeMemoMap"), () => new WeakMap());
579
+ const goMemo = (ast, isDecoding) => {
580
+ const memoMap = isDecoding ? decodeMemoMap : encodeMemoMap;
581
+ const memo = memoMap.get(ast);
582
+ if (memo) {
583
+ return memo;
584
+ }
585
+ const raw = go(ast, isDecoding);
586
+ const parseOptionsAnnotation = AST.getParseOptionsAnnotation(ast);
587
+ const parserWithOptions = Option.isSome(parseOptionsAnnotation) ? (i, options) => raw(i, mergeInternalOptions(options, parseOptionsAnnotation.value)) : raw;
588
+ const decodingFallbackAnnotation = AST.getDecodingFallbackAnnotation(ast);
589
+ const parser = isDecoding && Option.isSome(decodingFallbackAnnotation) ? (i, options) => handleForbidden(orElse(parserWithOptions(i, options), decodingFallbackAnnotation.value), ast, i, options) : parserWithOptions;
590
+ memoMap.set(ast, parser);
591
+ return parser;
592
+ };
593
+ const getConcurrency = ast => Option.getOrUndefined(AST.getConcurrencyAnnotation(ast));
594
+ const getBatching = ast => Option.getOrUndefined(AST.getBatchingAnnotation(ast));
595
+ const go = (ast, isDecoding) => {
596
+ switch (ast._tag) {
597
+ case "Refinement":
598
+ {
599
+ if (isDecoding) {
600
+ const from = goMemo(ast.from, true);
601
+ return (i, options) => {
602
+ options = options ?? AST.defaultParseOption;
603
+ const allErrors = options?.errors === "all";
604
+ const result = flatMap(orElse(from(i, options), ef => {
605
+ const issue = new Refinement(ast, i, "From", ef);
606
+ if (allErrors && AST.hasStableFilter(ast)) {
607
+ return Option.match(ast.filter(i, options, ast), {
608
+ onNone: () => Either.left(issue),
609
+ onSome: ep => Either.left(new Composite(ast, i, [issue, new Refinement(ast, i, "Predicate", ep)]))
610
+ });
611
+ }
612
+ return Either.left(issue);
613
+ }), a => Option.match(ast.filter(a, options, ast), {
614
+ onNone: () => Either.right(a),
615
+ onSome: ep => Either.left(new Refinement(ast, i, "Predicate", ep))
616
+ }));
617
+ return handleForbidden(result, ast, i, options);
618
+ };
619
+ } else {
620
+ const from = goMemo(AST.typeAST(ast), true);
621
+ const to = goMemo(dropRightRefinement(ast.from), false);
622
+ return (i, options) => handleForbidden(flatMap(from(i, options), a => to(a, options)), ast, i, options);
623
+ }
624
+ }
625
+ case "Transformation":
626
+ {
627
+ const transform = getFinalTransformation(ast.transformation, isDecoding);
628
+ const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false);
629
+ const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false);
630
+ return (i, options) => handleForbidden(flatMap(mapError(from(i, options), e => new Transformation(ast, i, isDecoding ? "Encoded" : "Type", e)), a => flatMap(mapError(transform(a, options ?? AST.defaultParseOption, ast, i), e => new Transformation(ast, i, "Transformation", e)), i2 => mapError(to(i2, options), e => new Transformation(ast, i, isDecoding ? "Type" : "Encoded", e)))), ast, i, options);
631
+ }
632
+ case "Declaration":
633
+ {
634
+ const parse = isDecoding ? ast.decodeUnknown(...ast.typeParameters) : ast.encodeUnknown(...ast.typeParameters);
635
+ return (i, options) => handleForbidden(parse(i, options ?? AST.defaultParseOption, ast), ast, i, options);
636
+ }
637
+ case "Literal":
638
+ return fromRefinement(ast, u => u === ast.literal);
639
+ case "UniqueSymbol":
640
+ return fromRefinement(ast, u => u === ast.symbol);
641
+ case "UndefinedKeyword":
642
+ return fromRefinement(ast, Predicate.isUndefined);
643
+ case "NeverKeyword":
644
+ return fromRefinement(ast, Predicate.isNever);
645
+ case "UnknownKeyword":
646
+ case "AnyKeyword":
647
+ case "VoidKeyword":
648
+ return Either.right;
649
+ case "StringKeyword":
650
+ return fromRefinement(ast, Predicate.isString);
651
+ case "NumberKeyword":
652
+ return fromRefinement(ast, Predicate.isNumber);
653
+ case "BooleanKeyword":
654
+ return fromRefinement(ast, Predicate.isBoolean);
655
+ case "BigIntKeyword":
656
+ return fromRefinement(ast, Predicate.isBigInt);
657
+ case "SymbolKeyword":
658
+ return fromRefinement(ast, Predicate.isSymbol);
659
+ case "ObjectKeyword":
660
+ return fromRefinement(ast, Predicate.isObject);
661
+ case "Enums":
662
+ return fromRefinement(ast, u => ast.enums.some(([_, value]) => value === u));
663
+ case "TemplateLiteral":
664
+ {
665
+ const regex = AST.getTemplateLiteralRegExp(ast);
666
+ return fromRefinement(ast, u => Predicate.isString(u) && regex.test(u));
667
+ }
668
+ case "TupleType":
669
+ {
670
+ const elements = ast.elements.map(e => goMemo(e.type, isDecoding));
671
+ const rest = ast.rest.map(annotatedAST => goMemo(annotatedAST.type, isDecoding));
672
+ let requiredTypes = ast.elements.filter(e => !e.isOptional);
673
+ if (ast.rest.length > 0) {
674
+ requiredTypes = requiredTypes.concat(ast.rest.slice(1));
675
+ }
676
+ const requiredLen = requiredTypes.length;
677
+ const expectedIndexes = ast.elements.length > 0 ? ast.elements.map((_, i) => i).join(" | ") : "never";
678
+ const concurrency = getConcurrency(ast);
679
+ const batching = getBatching(ast);
680
+ return (input, options) => {
681
+ if (!array_.isArray(input)) {
682
+ return Either.left(new Type(ast, input));
683
+ }
684
+ const allErrors = options?.errors === "all";
685
+ const es = [];
686
+ let stepKey = 0;
687
+ const output = [];
688
+ // ---------------------------------------------
689
+ // handle missing indexes
690
+ // ---------------------------------------------
691
+ const len = input.length;
692
+ for (let i = len; i <= requiredLen - 1; i++) {
693
+ const e = new Pointer(i, input, new Missing(requiredTypes[i - len]));
694
+ if (allErrors) {
695
+ es.push([stepKey++, e]);
696
+ continue;
697
+ } else {
698
+ return Either.left(new Composite(ast, input, e, output));
699
+ }
700
+ }
701
+ // ---------------------------------------------
702
+ // handle excess indexes
703
+ // ---------------------------------------------
704
+ if (ast.rest.length === 0) {
705
+ for (let i = ast.elements.length; i <= len - 1; i++) {
706
+ const e = new Pointer(i, input, new Unexpected(input[i], `is unexpected, expected: ${expectedIndexes}`));
707
+ if (allErrors) {
708
+ es.push([stepKey++, e]);
709
+ continue;
710
+ } else {
711
+ return Either.left(new Composite(ast, input, e, output));
712
+ }
713
+ }
714
+ }
715
+ let i = 0;
716
+ let queue = undefined;
717
+ // ---------------------------------------------
718
+ // handle elements
719
+ // ---------------------------------------------
720
+ for (; i < elements.length; i++) {
721
+ if (len < i + 1) {
722
+ if (ast.elements[i].isOptional) {
723
+ // the input element is missing
724
+ continue;
725
+ }
726
+ } else {
727
+ const parser = elements[i];
728
+ const te = parser(input[i], options);
729
+ const eu = eitherOrUndefined(te);
730
+ if (eu) {
731
+ if (Either.isLeft(eu)) {
732
+ // the input element is present but is not valid
733
+ const e = new Pointer(i, input, eu.left);
734
+ if (allErrors) {
735
+ es.push([stepKey++, e]);
736
+ continue;
737
+ } else {
738
+ return Either.left(new Composite(ast, input, e, sortByIndex(output)));
739
+ }
740
+ }
741
+ output.push([stepKey++, eu.right]);
742
+ } else {
743
+ const nk = stepKey++;
744
+ const index = i;
745
+ if (!queue) {
746
+ queue = [];
747
+ }
748
+ queue.push(({
749
+ es,
750
+ output
751
+ }) => Effect.flatMap(Effect.either(te), t => {
752
+ if (Either.isLeft(t)) {
753
+ // the input element is present but is not valid
754
+ const e = new Pointer(index, input, t.left);
755
+ if (allErrors) {
756
+ es.push([nk, e]);
757
+ return Effect.void;
758
+ } else {
759
+ return Either.left(new Composite(ast, input, e, sortByIndex(output)));
760
+ }
761
+ }
762
+ output.push([nk, t.right]);
763
+ return Effect.void;
764
+ }));
765
+ }
766
+ }
767
+ }
768
+ // ---------------------------------------------
769
+ // handle rest element
770
+ // ---------------------------------------------
771
+ if (array_.isNonEmptyReadonlyArray(rest)) {
772
+ const [head, ...tail] = rest;
773
+ for (; i < len - tail.length; i++) {
774
+ const te = head(input[i], options);
775
+ const eu = eitherOrUndefined(te);
776
+ if (eu) {
777
+ if (Either.isLeft(eu)) {
778
+ const e = new Pointer(i, input, eu.left);
779
+ if (allErrors) {
780
+ es.push([stepKey++, e]);
781
+ continue;
782
+ } else {
783
+ return Either.left(new Composite(ast, input, e, sortByIndex(output)));
784
+ }
785
+ } else {
786
+ output.push([stepKey++, eu.right]);
787
+ }
788
+ } else {
789
+ const nk = stepKey++;
790
+ const index = i;
791
+ if (!queue) {
792
+ queue = [];
793
+ }
794
+ queue.push(({
795
+ es,
796
+ output
797
+ }) => Effect.flatMap(Effect.either(te), t => {
798
+ if (Either.isLeft(t)) {
799
+ const e = new Pointer(index, input, t.left);
800
+ if (allErrors) {
801
+ es.push([nk, e]);
802
+ return Effect.void;
803
+ } else {
804
+ return Either.left(new Composite(ast, input, e, sortByIndex(output)));
805
+ }
806
+ } else {
807
+ output.push([nk, t.right]);
808
+ return Effect.void;
809
+ }
810
+ }));
811
+ }
812
+ }
813
+ // ---------------------------------------------
814
+ // handle post rest elements
815
+ // ---------------------------------------------
816
+ for (let j = 0; j < tail.length; j++) {
817
+ i += j;
818
+ if (len < i + 1) {
819
+ continue;
820
+ } else {
821
+ const te = tail[j](input[i], options);
822
+ const eu = eitherOrUndefined(te);
823
+ if (eu) {
824
+ if (Either.isLeft(eu)) {
825
+ // the input element is present but is not valid
826
+ const e = new Pointer(i, input, eu.left);
827
+ if (allErrors) {
828
+ es.push([stepKey++, e]);
829
+ continue;
830
+ } else {
831
+ return Either.left(new Composite(ast, input, e, sortByIndex(output)));
832
+ }
833
+ }
834
+ output.push([stepKey++, eu.right]);
835
+ } else {
836
+ const nk = stepKey++;
837
+ const index = i;
838
+ if (!queue) {
839
+ queue = [];
840
+ }
841
+ queue.push(({
842
+ es,
843
+ output
844
+ }) => Effect.flatMap(Effect.either(te), t => {
845
+ if (Either.isLeft(t)) {
846
+ // the input element is present but is not valid
847
+ const e = new Pointer(index, input, t.left);
848
+ if (allErrors) {
849
+ es.push([nk, e]);
850
+ return Effect.void;
851
+ } else {
852
+ return Either.left(new Composite(ast, input, e, sortByIndex(output)));
853
+ }
854
+ }
855
+ output.push([nk, t.right]);
856
+ return Effect.void;
857
+ }));
858
+ }
859
+ }
860
+ }
861
+ }
862
+ // ---------------------------------------------
863
+ // compute result
864
+ // ---------------------------------------------
865
+ const computeResult = ({
866
+ es,
867
+ output
868
+ }) => array_.isNonEmptyArray(es) ? Either.left(new Composite(ast, input, sortByIndex(es), sortByIndex(output))) : Either.right(sortByIndex(output));
869
+ if (queue && queue.length > 0) {
870
+ const cqueue = queue;
871
+ return Effect.suspend(() => {
872
+ const state = {
873
+ es: array_.copy(es),
874
+ output: array_.copy(output)
875
+ };
876
+ return Effect.flatMap(Effect.forEach(cqueue, f => f(state), {
877
+ concurrency,
878
+ batching,
879
+ discard: true
880
+ }), () => computeResult(state));
881
+ });
882
+ }
883
+ return computeResult({
884
+ output,
885
+ es
886
+ });
887
+ };
888
+ }
889
+ case "TypeLiteral":
890
+ {
891
+ if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) {
892
+ return fromRefinement(ast, Predicate.isNotNullable);
893
+ }
894
+ const propertySignatures = [];
895
+ const expectedKeysMap = {};
896
+ const expectedKeys = [];
897
+ for (const ps of ast.propertySignatures) {
898
+ propertySignatures.push([goMemo(ps.type, isDecoding), ps]);
899
+ expectedKeysMap[ps.name] = null;
900
+ expectedKeys.push(ps.name);
901
+ }
902
+ const indexSignatures = ast.indexSignatures.map(is => [goMemo(is.parameter, isDecoding), goMemo(is.type, isDecoding), is.parameter]);
903
+ const expectedAST = AST.Union.make(ast.indexSignatures.map(is => is.parameter).concat(expectedKeys.map(key => Predicate.isSymbol(key) ? new AST.UniqueSymbol(key) : new AST.Literal(key))));
904
+ const expected = goMemo(expectedAST, isDecoding);
905
+ const concurrency = getConcurrency(ast);
906
+ const batching = getBatching(ast);
907
+ return (input, options) => {
908
+ if (!Predicate.isRecord(input)) {
909
+ return Either.left(new Type(ast, input));
910
+ }
911
+ const allErrors = options?.errors === "all";
912
+ const es = [];
913
+ let stepKey = 0;
914
+ // ---------------------------------------------
915
+ // handle excess properties
916
+ // ---------------------------------------------
917
+ const onExcessPropertyError = options?.onExcessProperty === "error";
918
+ const onExcessPropertyPreserve = options?.onExcessProperty === "preserve";
919
+ const output = {};
920
+ let inputKeys;
921
+ if (onExcessPropertyError || onExcessPropertyPreserve) {
922
+ inputKeys = util_.ownKeys(input);
923
+ for (const key of inputKeys) {
924
+ const eu = eitherOrUndefined(expected(key, options));
925
+ if (Either.isLeft(eu)) {
926
+ // key is unexpected
927
+ if (onExcessPropertyError) {
928
+ const e = new Pointer(key, input, new Unexpected(input[key], `is unexpected, expected: ${String(expectedAST)}`));
929
+ if (allErrors) {
930
+ es.push([stepKey++, e]);
931
+ continue;
932
+ } else {
933
+ return Either.left(new Composite(ast, input, e, output));
934
+ }
935
+ } else {
936
+ // preserve key
937
+ output[key] = input[key];
938
+ }
939
+ }
940
+ }
941
+ }
942
+ let queue = undefined;
943
+ const isExact = options?.exact === true;
944
+ for (let i = 0; i < propertySignatures.length; i++) {
945
+ const ps = propertySignatures[i][1];
946
+ const name = ps.name;
947
+ const hasKey = Object.prototype.hasOwnProperty.call(input, name);
948
+ if (!hasKey) {
949
+ if (ps.isOptional) {
950
+ continue;
951
+ } else if (isExact) {
952
+ const e = new Pointer(name, input, new Missing(ps));
953
+ if (allErrors) {
954
+ es.push([stepKey++, e]);
955
+ continue;
956
+ } else {
957
+ return Either.left(new Composite(ast, input, e, output));
958
+ }
959
+ }
960
+ }
961
+ const parser = propertySignatures[i][0];
962
+ const te = parser(input[name], options);
963
+ const eu = eitherOrUndefined(te);
964
+ if (eu) {
965
+ if (Either.isLeft(eu)) {
966
+ const e = new Pointer(name, input, hasKey ? eu.left : new Missing(ps));
967
+ if (allErrors) {
968
+ es.push([stepKey++, e]);
969
+ continue;
970
+ } else {
971
+ return Either.left(new Composite(ast, input, e, output));
972
+ }
973
+ }
974
+ output[name] = eu.right;
975
+ } else {
976
+ const nk = stepKey++;
977
+ const index = name;
978
+ if (!queue) {
979
+ queue = [];
980
+ }
981
+ queue.push(({
982
+ es,
983
+ output
984
+ }) => Effect.flatMap(Effect.either(te), t => {
985
+ if (Either.isLeft(t)) {
986
+ const e = new Pointer(index, input, hasKey ? t.left : new Missing(ps));
987
+ if (allErrors) {
988
+ es.push([nk, e]);
989
+ return Effect.void;
990
+ } else {
991
+ return Either.left(new Composite(ast, input, e, output));
992
+ }
993
+ }
994
+ output[index] = t.right;
995
+ return Effect.void;
996
+ }));
997
+ }
998
+ }
999
+ // ---------------------------------------------
1000
+ // handle index signatures
1001
+ // ---------------------------------------------
1002
+ for (let i = 0; i < indexSignatures.length; i++) {
1003
+ const indexSignature = indexSignatures[i];
1004
+ const parameter = indexSignature[0];
1005
+ const type = indexSignature[1];
1006
+ const keys = util_.getKeysForIndexSignature(input, indexSignature[2]);
1007
+ for (const key of keys) {
1008
+ // ---------------------------------------------
1009
+ // handle keys
1010
+ // ---------------------------------------------
1011
+ const keu = eitherOrUndefined(parameter(key, options));
1012
+ if (keu && Either.isRight(keu)) {
1013
+ // ---------------------------------------------
1014
+ // handle values
1015
+ // ---------------------------------------------
1016
+ const vpr = type(input[key], options);
1017
+ const veu = eitherOrUndefined(vpr);
1018
+ if (veu) {
1019
+ if (Either.isLeft(veu)) {
1020
+ const e = new Pointer(key, input, veu.left);
1021
+ if (allErrors) {
1022
+ es.push([stepKey++, e]);
1023
+ continue;
1024
+ } else {
1025
+ return Either.left(new Composite(ast, input, e, output));
1026
+ }
1027
+ } else {
1028
+ if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
1029
+ output[key] = veu.right;
1030
+ }
1031
+ }
1032
+ } else {
1033
+ const nk = stepKey++;
1034
+ const index = key;
1035
+ if (!queue) {
1036
+ queue = [];
1037
+ }
1038
+ queue.push(({
1039
+ es,
1040
+ output
1041
+ }) => Effect.flatMap(Effect.either(vpr), tv => {
1042
+ if (Either.isLeft(tv)) {
1043
+ const e = new Pointer(index, input, tv.left);
1044
+ if (allErrors) {
1045
+ es.push([nk, e]);
1046
+ return Effect.void;
1047
+ } else {
1048
+ return Either.left(new Composite(ast, input, e, output));
1049
+ }
1050
+ } else {
1051
+ if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
1052
+ output[key] = tv.right;
1053
+ }
1054
+ return Effect.void;
1055
+ }
1056
+ }));
1057
+ }
1058
+ }
1059
+ }
1060
+ }
1061
+ // ---------------------------------------------
1062
+ // compute result
1063
+ // ---------------------------------------------
1064
+ const computeResult = ({
1065
+ es,
1066
+ output
1067
+ }) => {
1068
+ if (array_.isNonEmptyArray(es)) {
1069
+ return Either.left(new Composite(ast, input, sortByIndex(es), output));
1070
+ }
1071
+ if (options?.propertyOrder === "original") {
1072
+ // preserve input keys order
1073
+ const keys = inputKeys || util_.ownKeys(input);
1074
+ for (const name of expectedKeys) {
1075
+ if (keys.indexOf(name) === -1) {
1076
+ keys.push(name);
1077
+ }
1078
+ }
1079
+ const out = {};
1080
+ for (const key of keys) {
1081
+ if (Object.prototype.hasOwnProperty.call(output, key)) {
1082
+ out[key] = output[key];
1083
+ }
1084
+ }
1085
+ return Either.right(out);
1086
+ }
1087
+ return Either.right(output);
1088
+ };
1089
+ if (queue && queue.length > 0) {
1090
+ const cqueue = queue;
1091
+ return Effect.suspend(() => {
1092
+ const state = {
1093
+ es: array_.copy(es),
1094
+ output: Object.assign({}, output)
1095
+ };
1096
+ return Effect.flatMap(Effect.forEach(cqueue, f => f(state), {
1097
+ concurrency,
1098
+ batching,
1099
+ discard: true
1100
+ }), () => computeResult(state));
1101
+ });
1102
+ }
1103
+ return computeResult({
1104
+ es,
1105
+ output
1106
+ });
1107
+ };
1108
+ }
1109
+ case "Union":
1110
+ {
1111
+ const searchTree = getSearchTree(ast.types, isDecoding);
1112
+ const ownKeys = util_.ownKeys(searchTree.keys);
1113
+ const len = ownKeys.length;
1114
+ const map = new Map();
1115
+ for (let i = 0; i < ast.types.length; i++) {
1116
+ map.set(ast.types[i], goMemo(ast.types[i], isDecoding));
1117
+ }
1118
+ const concurrency = getConcurrency(ast) ?? 1;
1119
+ const batching = getBatching(ast);
1120
+ return (input, options) => {
1121
+ const es = [];
1122
+ let stepKey = 0;
1123
+ let candidates = [];
1124
+ if (len > 0) {
1125
+ if (Predicate.isRecordOrArray(input)) {
1126
+ for (let i = 0; i < len; i++) {
1127
+ const name = ownKeys[i];
1128
+ const buckets = searchTree.keys[name].buckets;
1129
+ // for each property that should contain a literal, check if the input contains that property
1130
+ if (Object.prototype.hasOwnProperty.call(input, name)) {
1131
+ const literal = String(input[name]);
1132
+ // check that the value obtained from the input for the property corresponds to an existing bucket
1133
+ if (Object.prototype.hasOwnProperty.call(buckets, literal)) {
1134
+ // retrive the minimal set of candidates for decoding
1135
+ candidates = candidates.concat(buckets[literal]);
1136
+ } else {
1137
+ const literals = AST.Union.make(searchTree.keys[name].literals);
1138
+ es.push([stepKey++, new Composite(new AST.TypeLiteral([new AST.PropertySignature(name, literals, false, true)], []), input, new Pointer(name, input, new Type(literals, input[name])))]);
1139
+ }
1140
+ } else {
1141
+ const literals = AST.Union.make(searchTree.keys[name].literals);
1142
+ const fakeps = new AST.PropertySignature(name, literals, false, true);
1143
+ es.push([stepKey++, new Composite(new AST.TypeLiteral([fakeps], []), input, new Pointer(name, input, new Missing(fakeps)))]);
1144
+ }
1145
+ }
1146
+ } else {
1147
+ es.push([stepKey++, new Type(ast, input)]);
1148
+ }
1149
+ }
1150
+ if (searchTree.otherwise.length > 0) {
1151
+ candidates = candidates.concat(searchTree.otherwise);
1152
+ }
1153
+ let queue = undefined;
1154
+ for (let i = 0; i < candidates.length; i++) {
1155
+ const candidate = candidates[i];
1156
+ const pr = map.get(candidate)(input, options);
1157
+ // the members of a union are ordered based on which one should be decoded first,
1158
+ // therefore if one member has added a task, all subsequent members must
1159
+ // also add a task to the queue even if they are synchronous
1160
+ const eu = !queue || queue.length === 0 ? eitherOrUndefined(pr) : undefined;
1161
+ if (eu) {
1162
+ if (Either.isRight(eu)) {
1163
+ return eu;
1164
+ } else {
1165
+ es.push([stepKey++, eu.left]);
1166
+ }
1167
+ } else {
1168
+ const nk = stepKey++;
1169
+ if (!queue) {
1170
+ queue = [];
1171
+ }
1172
+ queue.push(state => Effect.suspend(() => {
1173
+ if ("finalResult" in state) {
1174
+ return Effect.void;
1175
+ } else {
1176
+ return Effect.flatMap(Effect.either(pr), t => {
1177
+ if (Either.isRight(t)) {
1178
+ state.finalResult = t;
1179
+ } else {
1180
+ state.es.push([nk, t.left]);
1181
+ }
1182
+ return Effect.void;
1183
+ });
1184
+ }
1185
+ }));
1186
+ }
1187
+ }
1188
+ // ---------------------------------------------
1189
+ // compute result
1190
+ // ---------------------------------------------
1191
+ const computeResult = es => array_.isNonEmptyArray(es) ? es.length === 1 && es[0][1]._tag === "Type" ? Either.left(es[0][1]) : Either.left(new Composite(ast, input, sortByIndex(es))) :
1192
+ // this should never happen
1193
+ Either.left(new Type(ast, input));
1194
+ if (queue && queue.length > 0) {
1195
+ const cqueue = queue;
1196
+ return Effect.suspend(() => {
1197
+ const state = {
1198
+ es: array_.copy(es)
1199
+ };
1200
+ return Effect.flatMap(Effect.forEach(cqueue, f => f(state), {
1201
+ concurrency,
1202
+ batching,
1203
+ discard: true
1204
+ }), () => {
1205
+ if ("finalResult" in state) {
1206
+ return state.finalResult;
1207
+ }
1208
+ return computeResult(state.es);
1209
+ });
1210
+ });
1211
+ }
1212
+ return computeResult(es);
1213
+ };
1214
+ }
1215
+ case "Suspend":
1216
+ {
1217
+ const get = util_.memoizeThunk(() => goMemo(AST.annotations(ast.f(), ast.annotations), isDecoding));
1218
+ return (a, options) => get()(a, options);
1219
+ }
1220
+ }
1221
+ };
1222
+ const fromRefinement = (ast, refinement) => u => refinement(u) ? Either.right(u) : Either.left(new Type(ast, u));
1223
+ /** @internal */
1224
+ const getLiterals = (ast, isDecoding) => {
1225
+ switch (ast._tag) {
1226
+ case "Declaration":
1227
+ {
1228
+ const annotation = AST.getSurrogateAnnotation(ast);
1229
+ if (Option.isSome(annotation)) {
1230
+ return getLiterals(annotation.value, isDecoding);
1231
+ }
1232
+ break;
1233
+ }
1234
+ case "TypeLiteral":
1235
+ {
1236
+ const out = [];
1237
+ for (let i = 0; i < ast.propertySignatures.length; i++) {
1238
+ const propertySignature = ast.propertySignatures[i];
1239
+ const type = isDecoding ? AST.encodedAST(propertySignature.type) : AST.typeAST(propertySignature.type);
1240
+ if (AST.isLiteral(type) && !propertySignature.isOptional) {
1241
+ out.push([propertySignature.name, type]);
1242
+ }
1243
+ }
1244
+ return out;
1245
+ }
1246
+ case "TupleType":
1247
+ {
1248
+ const out = [];
1249
+ for (let i = 0; i < ast.elements.length; i++) {
1250
+ const element = ast.elements[i];
1251
+ const type = isDecoding ? AST.encodedAST(element.type) : AST.typeAST(element.type);
1252
+ if (AST.isLiteral(type) && !element.isOptional) {
1253
+ out.push([i, type]);
1254
+ }
1255
+ }
1256
+ return out;
1257
+ }
1258
+ case "Refinement":
1259
+ return getLiterals(ast.from, isDecoding);
1260
+ case "Suspend":
1261
+ return getLiterals(ast.f(), isDecoding);
1262
+ case "Transformation":
1263
+ return getLiterals(isDecoding ? ast.from : ast.to, isDecoding);
1264
+ }
1265
+ return [];
1266
+ };
1267
+ /**
1268
+ * The purpose of the algorithm is to narrow down the pool of possible candidates for decoding as much as possible.
1269
+ *
1270
+ * This function separates the schemas into two groups, `keys` and `otherwise`:
1271
+ *
1272
+ * - `keys`: the schema has at least one property with a literal value
1273
+ * - `otherwise`: the schema has no properties with a literal value
1274
+ *
1275
+ * If a schema has at least one property with a literal value, so it ends up in `keys`, first a namespace is created for
1276
+ * the name of the property containing the literal, and then within this namespace a "bucket" is created for the literal
1277
+ * value in which to store all the schemas that have the same property and literal value.
1278
+ *
1279
+ * @internal
1280
+ */
1281
+ exports.getLiterals = getLiterals;
1282
+ const getSearchTree = (members, isDecoding) => {
1283
+ const keys = {};
1284
+ const otherwise = [];
1285
+ for (let i = 0; i < members.length; i++) {
1286
+ const member = members[i];
1287
+ const tags = getLiterals(member, isDecoding);
1288
+ if (tags.length > 0) {
1289
+ for (let j = 0; j < tags.length; j++) {
1290
+ const [key, literal] = tags[j];
1291
+ const hash = String(literal.literal);
1292
+ keys[key] = keys[key] || {
1293
+ buckets: {},
1294
+ literals: []
1295
+ };
1296
+ const buckets = keys[key].buckets;
1297
+ if (Object.prototype.hasOwnProperty.call(buckets, hash)) {
1298
+ if (j < tags.length - 1) {
1299
+ continue;
1300
+ }
1301
+ buckets[hash].push(member);
1302
+ keys[key].literals.push(literal);
1303
+ } else {
1304
+ buckets[hash] = [member];
1305
+ keys[key].literals.push(literal);
1306
+ break;
1307
+ }
1308
+ }
1309
+ } else {
1310
+ otherwise.push(member);
1311
+ }
1312
+ }
1313
+ return {
1314
+ keys,
1315
+ otherwise
1316
+ };
1317
+ };
1318
+ exports.getSearchTree = getSearchTree;
1319
+ const dropRightRefinement = ast => AST.isRefinement(ast) ? dropRightRefinement(ast.from) : ast;
1320
+ const handleForbidden = (effect, ast, actual, options) => {
1321
+ const eu = eitherOrUndefined(effect);
1322
+ if (eu) {
1323
+ return eu;
1324
+ }
1325
+ if (options?.isEffectAllowed === true) {
1326
+ return effect;
1327
+ }
1328
+ try {
1329
+ return Effect.runSync(Effect.either(effect));
1330
+ } catch (e) {
1331
+ return Either.left(new Forbidden(ast, actual, "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"));
1332
+ }
1333
+ };
1334
+ const compare = ([a], [b]) => a > b ? 1 : a < b ? -1 : 0;
1335
+ function sortByIndex(es) {
1336
+ return es.sort(compare).map(t => t[1]);
1337
+ }
1338
+ // -------------------------------------------------------------------------------------
1339
+ // transformations interpreter
1340
+ // -------------------------------------------------------------------------------------
1341
+ /** @internal */
1342
+ const getFinalTransformation = (transformation, isDecoding) => {
1343
+ switch (transformation._tag) {
1344
+ case "FinalTransformation":
1345
+ return isDecoding ? transformation.decode : transformation.encode;
1346
+ case "ComposeTransformation":
1347
+ return Either.right;
1348
+ case "TypeLiteralTransformation":
1349
+ return input => {
1350
+ let out = Either.right(input);
1351
+ // ---------------------------------------------
1352
+ // handle property signature transformations
1353
+ // ---------------------------------------------
1354
+ for (const pst of transformation.propertySignatureTransformations) {
1355
+ const [from, to] = isDecoding ? [pst.from, pst.to] : [pst.to, pst.from];
1356
+ const transformation = isDecoding ? pst.decode : pst.encode;
1357
+ const f = input => {
1358
+ const o = transformation(Object.prototype.hasOwnProperty.call(input, from) ? Option.some(input[from]) : Option.none());
1359
+ delete input[from];
1360
+ if (Option.isSome(o)) {
1361
+ input[to] = o.value;
1362
+ }
1363
+ return input;
1364
+ };
1365
+ out = map(out, f);
1366
+ }
1367
+ return out;
1368
+ };
1369
+ }
1370
+ };
1371
+ exports.getFinalTransformation = getFinalTransformation;
1372
+ const makeTree = (value, forest = []) => ({
1373
+ value,
1374
+ forest
1375
+ });
1376
+ /**
1377
+ * @category formatting
1378
+ * @since 3.10.0
1379
+ */
1380
+ const TreeFormatter = exports.TreeFormatter = {
1381
+ formatIssue: issue => Effect.map(formatTree(issue), drawTree),
1382
+ formatIssueSync: issue => Effect.runSync(TreeFormatter.formatIssue(issue)),
1383
+ formatError: error => TreeFormatter.formatIssue(error.issue),
1384
+ formatErrorSync: error => TreeFormatter.formatIssueSync(error.issue)
1385
+ };
1386
+ const drawTree = tree => tree.value + draw("\n", tree.forest);
1387
+ const draw = (indentation, forest) => {
1388
+ let r = "";
1389
+ const len = forest.length;
1390
+ let tree;
1391
+ for (let i = 0; i < len; i++) {
1392
+ tree = forest[i];
1393
+ const isLast = i === len - 1;
1394
+ r += indentation + (isLast ? "└" : "├") + "─ " + tree.value;
1395
+ r += draw(indentation + (len > 1 && !isLast ? "│ " : " "), tree.forest);
1396
+ }
1397
+ return r;
1398
+ };
1399
+ const formatTransformationKind = kind => {
1400
+ switch (kind) {
1401
+ case "Encoded":
1402
+ return "Encoded side transformation failure";
1403
+ case "Transformation":
1404
+ return "Transformation process failure";
1405
+ case "Type":
1406
+ return "Type side transformation failure";
1407
+ }
1408
+ };
1409
+ const formatRefinementKind = kind => {
1410
+ switch (kind) {
1411
+ case "From":
1412
+ return "From side refinement failure";
1413
+ case "Predicate":
1414
+ return "Predicate refinement failure";
1415
+ }
1416
+ };
1417
+ const getAnnotated = issue => "ast" in issue ? Option.some(issue.ast) : Option.none();
1418
+ const getCurrentMessage = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getMessageAnnotation), Effect.flatMap(annotation => {
1419
+ const out = annotation(issue);
1420
+ return Predicate.isString(out) ? Effect.succeed({
1421
+ message: out,
1422
+ override: false
1423
+ }) : Effect.isEffect(out) ? Effect.map(out, message => ({
1424
+ message,
1425
+ override: false
1426
+ })) : Predicate.isString(out.message) ? Effect.succeed({
1427
+ message: out.message,
1428
+ override: out.override
1429
+ }) : Effect.map(out.message, message => ({
1430
+ message,
1431
+ override: out.override
1432
+ }));
1433
+ }));
1434
+ const createParseIssueGuard = tag => issue => issue._tag === tag;
1435
+ /**
1436
+ * Returns `true` if the value is a `Composite`.
1437
+ *
1438
+ * @category guards
1439
+ * @since 3.10.0
1440
+ */
1441
+ const isComposite = exports.isComposite = /*#__PURE__*/createParseIssueGuard("Composite");
1442
+ const isRefinement = /*#__PURE__*/createParseIssueGuard("Refinement");
1443
+ const isTransformation = /*#__PURE__*/createParseIssueGuard("Transformation");
1444
+ const getMessage = issue => getCurrentMessage(issue).pipe(Effect.flatMap(currentMessage => {
1445
+ const useInnerMessage = !currentMessage.override && (isComposite(issue) || isRefinement(issue) && issue.kind === "From" || isTransformation(issue) && issue.kind !== "Transformation");
1446
+ return useInnerMessage ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Option.none() : Effect.succeed(currentMessage.message);
1447
+ }));
1448
+ const getParseIssueTitleAnnotation = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getParseIssueTitleAnnotation), Option.filterMap(annotation => Option.fromNullable(annotation(issue))));
1449
+ const formatTypeMessage = e => getMessage(e).pipe(Effect.orElse(() => getParseIssueTitleAnnotation(e)), Effect.catchAll(() => Effect.succeed(e.message ?? `Expected ${String(e.ast)}, actual ${util_.formatUnknown(e.actual)}`)));
1450
+ const getParseIssueTitle = issue => Option.getOrElse(getParseIssueTitleAnnotation(issue), () => String(issue.ast));
1451
+ const formatForbiddenMessage = e => e.message ?? "is forbidden";
1452
+ const formatUnexpectedMessage = e => e.message ?? "is unexpected";
1453
+ const formatMissingMessage = e => AST.getMissingMessageAnnotation(e.ast).pipe(Effect.flatMap(annotation => {
1454
+ const out = annotation();
1455
+ return Predicate.isString(out) ? Effect.succeed(out) : out;
1456
+ }), Effect.catchAll(() => Effect.succeed(e.message ?? "is missing")));
1457
+ const getTree = (issue, onFailure) => Effect.matchEffect(getMessage(issue), {
1458
+ onFailure,
1459
+ onSuccess: message => Effect.succeed(makeTree(message))
1460
+ });
1461
+ const formatTree = e => {
1462
+ switch (e._tag) {
1463
+ case "Type":
1464
+ return Effect.map(formatTypeMessage(e), makeTree);
1465
+ case "Forbidden":
1466
+ return Effect.succeed(makeTree(getParseIssueTitle(e), [makeTree(formatForbiddenMessage(e))]));
1467
+ case "Unexpected":
1468
+ return Effect.succeed(makeTree(formatUnexpectedMessage(e)));
1469
+ case "Missing":
1470
+ return Effect.map(formatMissingMessage(e), makeTree);
1471
+ case "Transformation":
1472
+ return getTree(e, () => Effect.map(formatTree(e.issue), tree => makeTree(getParseIssueTitle(e), [makeTree(formatTransformationKind(e.kind), [tree])])));
1473
+ case "Refinement":
1474
+ return getTree(e, () => Effect.map(formatTree(e.issue), tree => makeTree(getParseIssueTitle(e), [makeTree(formatRefinementKind(e.kind), [tree])])));
1475
+ case "Pointer":
1476
+ return Effect.map(formatTree(e.issue), tree => makeTree(util_.formatPath(e.path), [tree]));
1477
+ case "Composite":
1478
+ {
1479
+ const parseIssueTitle = getParseIssueTitle(e);
1480
+ return getTree(e, () => util_.isNonEmpty(e.issues) ? Effect.map(Effect.forEach(e.issues, formatTree), forest => makeTree(parseIssueTitle, forest)) : Effect.map(formatTree(e.issues), tree => makeTree(parseIssueTitle, [tree])));
1481
+ }
1482
+ }
1483
+ };
1484
+ /**
1485
+ * @category formatting
1486
+ * @since 3.10.0
1487
+ */
1488
+ const ArrayFormatter = exports.ArrayFormatter = {
1489
+ formatIssue: issue => formatArray(issue),
1490
+ formatIssueSync: issue => Effect.runSync(ArrayFormatter.formatIssue(issue)),
1491
+ formatError: error => ArrayFormatter.formatIssue(error.issue),
1492
+ formatErrorSync: error => ArrayFormatter.formatIssueSync(error.issue)
1493
+ };
1494
+ const succeedArrayFormatterIssue = issue => Effect.succeed([issue]);
1495
+ const getArray = (issue, path, onFailure) => Effect.matchEffect(getMessage(issue), {
1496
+ onFailure,
1497
+ onSuccess: message => succeedArrayFormatterIssue({
1498
+ _tag: issue._tag,
1499
+ path,
1500
+ message
1501
+ })
1502
+ });
1503
+ const formatArray = (e, path = []) => {
1504
+ const _tag = e._tag;
1505
+ switch (_tag) {
1506
+ case "Type":
1507
+ return Effect.map(formatTypeMessage(e), message => [{
1508
+ _tag,
1509
+ path,
1510
+ message
1511
+ }]);
1512
+ case "Forbidden":
1513
+ return succeedArrayFormatterIssue({
1514
+ _tag,
1515
+ path,
1516
+ message: formatForbiddenMessage(e)
1517
+ });
1518
+ case "Unexpected":
1519
+ return succeedArrayFormatterIssue({
1520
+ _tag,
1521
+ path,
1522
+ message: formatUnexpectedMessage(e)
1523
+ });
1524
+ case "Missing":
1525
+ return Effect.map(formatMissingMessage(e), message => [{
1526
+ _tag,
1527
+ path,
1528
+ message
1529
+ }]);
1530
+ case "Pointer":
1531
+ return formatArray(e.issue, path.concat(e.path));
1532
+ case "Composite":
1533
+ return getArray(e, path, () => util_.isNonEmpty(e.issues) ? Effect.map(Effect.forEach(e.issues, issue => formatArray(issue, path)), array_.flatten) : formatArray(e.issues, path));
1534
+ case "Refinement":
1535
+ case "Transformation":
1536
+ return getArray(e, path, () => formatArray(e.issue, path));
1537
+ }
1538
+ };
1539
+ //# sourceMappingURL=ParseResult.js.map