@clayroach/effect 3.19.14-source-capture.7 → 3.19.14-source-capture.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/dist/cjs/Utils.js +1 -1
  2. package/dist/cjs/Utils.js.map +1 -1
  3. package/dist/cjs/internal/clock.js +1 -1
  4. package/dist/cjs/internal/clock.js.map +1 -1
  5. package/dist/esm/Utils.js +1 -1
  6. package/dist/esm/Utils.js.map +1 -1
  7. package/dist/esm/internal/clock.js +1 -1
  8. package/dist/esm/internal/clock.js.map +1 -1
  9. package/package.json +1 -1
  10. package/src/Arbitrary.ts +0 -1101
  11. package/src/Array.ts +0 -3589
  12. package/src/BigDecimal.ts +0 -1349
  13. package/src/BigInt.ts +0 -643
  14. package/src/Boolean.ts +0 -287
  15. package/src/Brand.ts +0 -360
  16. package/src/Cache.ts +0 -281
  17. package/src/Cause.ts +0 -1555
  18. package/src/Channel.ts +0 -2355
  19. package/src/ChildExecutorDecision.ts +0 -146
  20. package/src/Chunk.ts +0 -1495
  21. package/src/Clock.ts +0 -111
  22. package/src/Config.ts +0 -542
  23. package/src/ConfigError.ts +0 -270
  24. package/src/ConfigProvider.ts +0 -333
  25. package/src/ConfigProviderPathPatch.ts +0 -100
  26. package/src/Console.ts +0 -226
  27. package/src/Context.ts +0 -585
  28. package/src/Cron.ts +0 -706
  29. package/src/Data.ts +0 -596
  30. package/src/DateTime.ts +0 -1686
  31. package/src/DefaultServices.ts +0 -34
  32. package/src/Deferred.ts +0 -301
  33. package/src/Differ.ts +0 -450
  34. package/src/Duration.ts +0 -1000
  35. package/src/Effect.ts +0 -14839
  36. package/src/Effectable.ts +0 -107
  37. package/src/Either.ts +0 -1040
  38. package/src/Encoding.ts +0 -195
  39. package/src/Equal.ts +0 -98
  40. package/src/Equivalence.ts +0 -235
  41. package/src/ExecutionPlan.ts +0 -308
  42. package/src/ExecutionStrategy.ts +0 -119
  43. package/src/Exit.ts +0 -467
  44. package/src/FastCheck.ts +0 -9
  45. package/src/Fiber.ts +0 -744
  46. package/src/FiberHandle.ts +0 -540
  47. package/src/FiberId.ts +0 -195
  48. package/src/FiberMap.ts +0 -656
  49. package/src/FiberRef.ts +0 -431
  50. package/src/FiberRefs.ts +0 -204
  51. package/src/FiberRefsPatch.ts +0 -105
  52. package/src/FiberSet.ts +0 -491
  53. package/src/FiberStatus.ts +0 -108
  54. package/src/Function.ts +0 -1222
  55. package/src/GlobalValue.ts +0 -53
  56. package/src/Graph.ts +0 -3732
  57. package/src/GroupBy.ts +0 -103
  58. package/src/HKT.ts +0 -45
  59. package/src/Hash.ts +0 -195
  60. package/src/HashMap.ts +0 -519
  61. package/src/HashRing.ts +0 -317
  62. package/src/HashSet.ts +0 -2346
  63. package/src/Inspectable.ts +0 -287
  64. package/src/Iterable.ts +0 -1119
  65. package/src/JSONSchema.ts +0 -1044
  66. package/src/KeyedPool.ts +0 -167
  67. package/src/Layer.ts +0 -1251
  68. package/src/LayerMap.ts +0 -436
  69. package/src/List.ts +0 -977
  70. package/src/LogLevel.ts +0 -285
  71. package/src/LogSpan.ts +0 -25
  72. package/src/Logger.ts +0 -702
  73. package/src/Mailbox.ts +0 -268
  74. package/src/ManagedRuntime.ts +0 -180
  75. package/src/Match.ts +0 -1477
  76. package/src/MergeDecision.ts +0 -95
  77. package/src/MergeState.ts +0 -172
  78. package/src/MergeStrategy.ts +0 -107
  79. package/src/Metric.ts +0 -780
  80. package/src/MetricBoundaries.ts +0 -69
  81. package/src/MetricHook.ts +0 -151
  82. package/src/MetricKey.ts +0 -224
  83. package/src/MetricKeyType.ts +0 -262
  84. package/src/MetricLabel.ts +0 -47
  85. package/src/MetricPair.ts +0 -71
  86. package/src/MetricPolling.ts +0 -148
  87. package/src/MetricRegistry.ts +0 -48
  88. package/src/MetricState.ts +0 -257
  89. package/src/Micro.ts +0 -4405
  90. package/src/ModuleVersion.ts +0 -18
  91. package/src/MutableHashMap.ts +0 -411
  92. package/src/MutableHashSet.ts +0 -706
  93. package/src/MutableList.ts +0 -297
  94. package/src/MutableQueue.ts +0 -227
  95. package/src/MutableRef.ts +0 -202
  96. package/src/NonEmptyIterable.ts +0 -32
  97. package/src/Number.ts +0 -1071
  98. package/src/Option.ts +0 -2170
  99. package/src/Order.ts +0 -373
  100. package/src/Ordering.ts +0 -111
  101. package/src/ParseResult.ts +0 -2031
  102. package/src/PartitionedSemaphore.ts +0 -200
  103. package/src/Pipeable.ts +0 -566
  104. package/src/Pool.ts +0 -204
  105. package/src/Predicate.ts +0 -1405
  106. package/src/Pretty.ts +0 -205
  107. package/src/PrimaryKey.ts +0 -23
  108. package/src/PubSub.ts +0 -182
  109. package/src/Queue.ts +0 -644
  110. package/src/Random.ts +0 -204
  111. package/src/RateLimiter.ts +0 -138
  112. package/src/RcMap.ts +0 -141
  113. package/src/RcRef.ts +0 -122
  114. package/src/Readable.ts +0 -93
  115. package/src/Record.ts +0 -1274
  116. package/src/RedBlackTree.ts +0 -421
  117. package/src/Redacted.ts +0 -144
  118. package/src/Ref.ts +0 -180
  119. package/src/RegExp.ts +0 -38
  120. package/src/Reloadable.ts +0 -127
  121. package/src/Request.ts +0 -347
  122. package/src/RequestBlock.ts +0 -118
  123. package/src/RequestResolver.ts +0 -366
  124. package/src/Resource.ts +0 -119
  125. package/src/Runtime.ts +0 -383
  126. package/src/RuntimeFlags.ts +0 -368
  127. package/src/RuntimeFlagsPatch.ts +0 -183
  128. package/src/STM.ts +0 -2045
  129. package/src/Schedule.ts +0 -2219
  130. package/src/ScheduleDecision.ts +0 -62
  131. package/src/ScheduleInterval.ts +0 -151
  132. package/src/ScheduleIntervals.ts +0 -122
  133. package/src/Scheduler.ts +0 -353
  134. package/src/Schema.ts +0 -10914
  135. package/src/SchemaAST.ts +0 -3043
  136. package/src/Scope.ts +0 -204
  137. package/src/ScopedCache.ts +0 -151
  138. package/src/ScopedRef.ts +0 -117
  139. package/src/Secret.ts +0 -88
  140. package/src/SingleProducerAsyncInput.ts +0 -67
  141. package/src/Sink.ts +0 -1461
  142. package/src/SortedMap.ts +0 -287
  143. package/src/SortedSet.ts +0 -390
  144. package/src/Stream.ts +0 -6468
  145. package/src/StreamEmit.ts +0 -136
  146. package/src/StreamHaltStrategy.ts +0 -123
  147. package/src/Streamable.ts +0 -45
  148. package/src/String.ts +0 -778
  149. package/src/Struct.ts +0 -243
  150. package/src/Subscribable.ts +0 -100
  151. package/src/SubscriptionRef.ts +0 -298
  152. package/src/Supervisor.ts +0 -240
  153. package/src/Symbol.ts +0 -29
  154. package/src/SynchronizedRef.ts +0 -270
  155. package/src/TArray.ts +0 -495
  156. package/src/TDeferred.ts +0 -100
  157. package/src/TMap.ts +0 -515
  158. package/src/TPriorityQueue.ts +0 -223
  159. package/src/TPubSub.ts +0 -200
  160. package/src/TQueue.ts +0 -432
  161. package/src/TRandom.ts +0 -129
  162. package/src/TReentrantLock.ts +0 -224
  163. package/src/TRef.ts +0 -178
  164. package/src/TSemaphore.ts +0 -129
  165. package/src/TSet.ts +0 -365
  166. package/src/TSubscriptionRef.ts +0 -192
  167. package/src/Take.ts +0 -258
  168. package/src/TestAnnotation.ts +0 -158
  169. package/src/TestAnnotationMap.ts +0 -119
  170. package/src/TestAnnotations.ts +0 -117
  171. package/src/TestClock.ts +0 -556
  172. package/src/TestConfig.ts +0 -47
  173. package/src/TestContext.ts +0 -36
  174. package/src/TestLive.ts +0 -53
  175. package/src/TestServices.ts +0 -390
  176. package/src/TestSized.ts +0 -55
  177. package/src/Tracer.ts +0 -198
  178. package/src/Trie.ts +0 -840
  179. package/src/Tuple.ts +0 -305
  180. package/src/Types.ts +0 -353
  181. package/src/Unify.ts +0 -113
  182. package/src/UpstreamPullRequest.ts +0 -117
  183. package/src/UpstreamPullStrategy.ts +0 -121
  184. package/src/Utils.ts +0 -809
  185. package/src/index.ts +0 -1561
  186. package/src/internal/array.ts +0 -8
  187. package/src/internal/blockedRequests.ts +0 -520
  188. package/src/internal/cache.ts +0 -733
  189. package/src/internal/cause.ts +0 -1050
  190. package/src/internal/channel/channelExecutor.ts +0 -1200
  191. package/src/internal/channel/channelState.ts +0 -134
  192. package/src/internal/channel/childExecutorDecision.ts +0 -96
  193. package/src/internal/channel/continuation.ts +0 -200
  194. package/src/internal/channel/mergeDecision.ts +0 -113
  195. package/src/internal/channel/mergeState.ts +0 -120
  196. package/src/internal/channel/mergeStrategy.ts +0 -72
  197. package/src/internal/channel/singleProducerAsyncInput.ts +0 -259
  198. package/src/internal/channel/subexecutor.ts +0 -229
  199. package/src/internal/channel/upstreamPullRequest.ts +0 -84
  200. package/src/internal/channel/upstreamPullStrategy.ts +0 -87
  201. package/src/internal/channel.ts +0 -2603
  202. package/src/internal/clock.ts +0 -95
  203. package/src/internal/completedRequestMap.ts +0 -9
  204. package/src/internal/concurrency.ts +0 -54
  205. package/src/internal/config.ts +0 -716
  206. package/src/internal/configError.ts +0 -304
  207. package/src/internal/configProvider/pathPatch.ts +0 -97
  208. package/src/internal/configProvider.ts +0 -799
  209. package/src/internal/console.ts +0 -153
  210. package/src/internal/context.ts +0 -337
  211. package/src/internal/core-effect.ts +0 -2293
  212. package/src/internal/core-stream.ts +0 -998
  213. package/src/internal/core.ts +0 -3273
  214. package/src/internal/data.ts +0 -36
  215. package/src/internal/dataSource.ts +0 -327
  216. package/src/internal/dateTime.ts +0 -1277
  217. package/src/internal/defaultServices/console.ts +0 -100
  218. package/src/internal/defaultServices.ts +0 -163
  219. package/src/internal/deferred.ts +0 -46
  220. package/src/internal/differ/chunkPatch.ts +0 -211
  221. package/src/internal/differ/contextPatch.ts +0 -232
  222. package/src/internal/differ/hashMapPatch.ts +0 -220
  223. package/src/internal/differ/hashSetPatch.ts +0 -176
  224. package/src/internal/differ/orPatch.ts +0 -311
  225. package/src/internal/differ/readonlyArrayPatch.ts +0 -210
  226. package/src/internal/differ.ts +0 -200
  227. package/src/internal/doNotation.ts +0 -80
  228. package/src/internal/effect/circular.ts +0 -905
  229. package/src/internal/effectable.ts +0 -131
  230. package/src/internal/either.ts +0 -110
  231. package/src/internal/encoding/base64.ts +0 -286
  232. package/src/internal/encoding/base64Url.ts +0 -29
  233. package/src/internal/encoding/common.ts +0 -51
  234. package/src/internal/encoding/hex.ts +0 -315
  235. package/src/internal/errors.ts +0 -7
  236. package/src/internal/executionPlan.ts +0 -114
  237. package/src/internal/executionStrategy.ts +0 -74
  238. package/src/internal/fiber.ts +0 -388
  239. package/src/internal/fiberId.ts +0 -267
  240. package/src/internal/fiberMessage.ts +0 -82
  241. package/src/internal/fiberRefs/patch.ts +0 -144
  242. package/src/internal/fiberRefs.ts +0 -297
  243. package/src/internal/fiberRuntime.ts +0 -3915
  244. package/src/internal/fiberScope.ts +0 -71
  245. package/src/internal/fiberStatus.ts +0 -119
  246. package/src/internal/groupBy.ts +0 -530
  247. package/src/internal/hashMap/array.ts +0 -49
  248. package/src/internal/hashMap/bitwise.ts +0 -32
  249. package/src/internal/hashMap/config.ts +0 -14
  250. package/src/internal/hashMap/keySet.ts +0 -8
  251. package/src/internal/hashMap/node.ts +0 -391
  252. package/src/internal/hashMap.ts +0 -586
  253. package/src/internal/hashSet.ts +0 -323
  254. package/src/internal/keyedPool.ts +0 -244
  255. package/src/internal/layer/circular.ts +0 -228
  256. package/src/internal/layer.ts +0 -1487
  257. package/src/internal/logSpan.ts +0 -20
  258. package/src/internal/logger-circular.ts +0 -24
  259. package/src/internal/logger.ts +0 -485
  260. package/src/internal/mailbox.ts +0 -561
  261. package/src/internal/managedRuntime/circular.ts +0 -6
  262. package/src/internal/managedRuntime.ts +0 -134
  263. package/src/internal/matcher.ts +0 -652
  264. package/src/internal/metric/boundaries.ts +0 -75
  265. package/src/internal/metric/hook.ts +0 -483
  266. package/src/internal/metric/key.ts +0 -167
  267. package/src/internal/metric/keyType.ts +0 -238
  268. package/src/internal/metric/label.ts +0 -41
  269. package/src/internal/metric/pair.ts +0 -48
  270. package/src/internal/metric/polling.ts +0 -149
  271. package/src/internal/metric/registry.ts +0 -187
  272. package/src/internal/metric/state.ts +0 -290
  273. package/src/internal/metric.ts +0 -577
  274. package/src/internal/opCodes/cause.ts +0 -35
  275. package/src/internal/opCodes/channel.ts +0 -83
  276. package/src/internal/opCodes/channelChildExecutorDecision.ts +0 -17
  277. package/src/internal/opCodes/channelMergeDecision.ts +0 -11
  278. package/src/internal/opCodes/channelMergeState.ts +0 -17
  279. package/src/internal/opCodes/channelMergeStrategy.ts +0 -11
  280. package/src/internal/opCodes/channelState.ts +0 -23
  281. package/src/internal/opCodes/channelUpstreamPullRequest.ts +0 -11
  282. package/src/internal/opCodes/channelUpstreamPullStrategy.ts +0 -11
  283. package/src/internal/opCodes/config.ts +0 -65
  284. package/src/internal/opCodes/configError.ts +0 -35
  285. package/src/internal/opCodes/continuation.ts +0 -11
  286. package/src/internal/opCodes/deferred.ts +0 -11
  287. package/src/internal/opCodes/effect.ts +0 -89
  288. package/src/internal/opCodes/layer.ts +0 -59
  289. package/src/internal/opCodes/streamHaltStrategy.ts +0 -23
  290. package/src/internal/option.ts +0 -80
  291. package/src/internal/pool.ts +0 -432
  292. package/src/internal/pubsub.ts +0 -1762
  293. package/src/internal/query.ts +0 -204
  294. package/src/internal/queue.ts +0 -766
  295. package/src/internal/random.ts +0 -161
  296. package/src/internal/rateLimiter.ts +0 -93
  297. package/src/internal/rcMap.ts +0 -285
  298. package/src/internal/rcRef.ts +0 -192
  299. package/src/internal/redBlackTree/iterator.ts +0 -200
  300. package/src/internal/redBlackTree/node.ts +0 -68
  301. package/src/internal/redBlackTree.ts +0 -1245
  302. package/src/internal/redacted.ts +0 -73
  303. package/src/internal/ref.ts +0 -171
  304. package/src/internal/reloadable.ts +0 -140
  305. package/src/internal/request.ts +0 -177
  306. package/src/internal/resource.ts +0 -76
  307. package/src/internal/ringBuffer.ts +0 -68
  308. package/src/internal/runtime.ts +0 -558
  309. package/src/internal/runtimeFlags.ts +0 -188
  310. package/src/internal/runtimeFlagsPatch.ts +0 -103
  311. package/src/internal/schedule/decision.ts +0 -47
  312. package/src/internal/schedule/interval.ts +0 -101
  313. package/src/internal/schedule/intervals.ts +0 -180
  314. package/src/internal/schedule.ts +0 -2199
  315. package/src/internal/schema/errors.ts +0 -191
  316. package/src/internal/schema/schemaId.ts +0 -106
  317. package/src/internal/schema/util.ts +0 -50
  318. package/src/internal/scopedCache.ts +0 -644
  319. package/src/internal/scopedRef.ts +0 -118
  320. package/src/internal/secret.ts +0 -89
  321. package/src/internal/singleShotGen.ts +0 -35
  322. package/src/internal/sink.ts +0 -2120
  323. package/src/internal/stack.ts +0 -10
  324. package/src/internal/stm/core.ts +0 -817
  325. package/src/internal/stm/entry.ts +0 -59
  326. package/src/internal/stm/journal.ts +0 -123
  327. package/src/internal/stm/opCodes/stm.ts +0 -71
  328. package/src/internal/stm/opCodes/stmState.ts +0 -17
  329. package/src/internal/stm/opCodes/strategy.ts +0 -17
  330. package/src/internal/stm/opCodes/tExit.ts +0 -29
  331. package/src/internal/stm/opCodes/tryCommit.ts +0 -11
  332. package/src/internal/stm/stm.ts +0 -1453
  333. package/src/internal/stm/stmState.ts +0 -136
  334. package/src/internal/stm/tArray.ts +0 -550
  335. package/src/internal/stm/tDeferred.ts +0 -81
  336. package/src/internal/stm/tExit.ts +0 -190
  337. package/src/internal/stm/tMap.ts +0 -824
  338. package/src/internal/stm/tPriorityQueue.ts +0 -267
  339. package/src/internal/stm/tPubSub.ts +0 -551
  340. package/src/internal/stm/tQueue.ts +0 -393
  341. package/src/internal/stm/tRandom.ts +0 -140
  342. package/src/internal/stm/tReentrantLock.ts +0 -352
  343. package/src/internal/stm/tRef.ts +0 -195
  344. package/src/internal/stm/tSemaphore.ts +0 -113
  345. package/src/internal/stm/tSet.ts +0 -259
  346. package/src/internal/stm/tSubscriptionRef.ts +0 -286
  347. package/src/internal/stm/tryCommit.ts +0 -34
  348. package/src/internal/stm/txnId.ts +0 -14
  349. package/src/internal/stm/versioned.ts +0 -4
  350. package/src/internal/stream/debounceState.ts +0 -57
  351. package/src/internal/stream/emit.ts +0 -123
  352. package/src/internal/stream/haltStrategy.ts +0 -94
  353. package/src/internal/stream/handoff.ts +0 -187
  354. package/src/internal/stream/handoffSignal.ts +0 -59
  355. package/src/internal/stream/pull.ts +0 -34
  356. package/src/internal/stream/sinkEndReason.ts +0 -30
  357. package/src/internal/stream/zipAllState.ts +0 -88
  358. package/src/internal/stream/zipChunksState.ts +0 -56
  359. package/src/internal/stream.ts +0 -8801
  360. package/src/internal/string-utils.ts +0 -107
  361. package/src/internal/subscriptionRef.ts +0 -138
  362. package/src/internal/supervisor/patch.ts +0 -190
  363. package/src/internal/supervisor.ts +0 -303
  364. package/src/internal/synchronizedRef.ts +0 -114
  365. package/src/internal/take.ts +0 -199
  366. package/src/internal/testing/sleep.ts +0 -27
  367. package/src/internal/testing/suspendedWarningData.ts +0 -85
  368. package/src/internal/testing/warningData.ts +0 -94
  369. package/src/internal/tracer.ts +0 -293
  370. package/src/internal/trie.ts +0 -722
  371. package/src/internal/version.ts +0 -7
@@ -1,2031 +0,0 @@
1
- /**
2
- * @since 3.10.0
3
- */
4
-
5
- import * as Arr from "./Array.js"
6
- import * as Cause from "./Cause.js"
7
- import { TaggedError } from "./Data.js"
8
- import * as Effect from "./Effect.js"
9
- import * as Either from "./Either.js"
10
- import * as Exit from "./Exit.js"
11
- import type { LazyArg } from "./Function.js"
12
- import { dual } from "./Function.js"
13
- import { globalValue } from "./GlobalValue.js"
14
- import * as Inspectable from "./Inspectable.js"
15
- import * as util_ from "./internal/schema/util.js"
16
- import * as Option from "./Option.js"
17
- import * as Predicate from "./Predicate.js"
18
- import * as Scheduler from "./Scheduler.js"
19
- import type * as Schema from "./Schema.js"
20
- import * as AST from "./SchemaAST.js"
21
- import type { Concurrency } from "./Types.js"
22
-
23
- /**
24
- * `ParseIssue` is a type that represents the different types of errors that can occur when decoding/encoding a value.
25
- *
26
- * @category model
27
- * @since 3.10.0
28
- */
29
- export type ParseIssue =
30
- // leaf
31
- | Type
32
- | Missing
33
- | Unexpected
34
- | Forbidden
35
- // composite
36
- | Pointer
37
- | Refinement
38
- | Transformation
39
- | Composite
40
-
41
- /**
42
- * @category model
43
- * @since 3.10.0
44
- */
45
- export type SingleOrNonEmpty<A> = A | Arr.NonEmptyReadonlyArray<A>
46
-
47
- /**
48
- * @category model
49
- * @since 3.10.0
50
- */
51
- export type Path = SingleOrNonEmpty<PropertyKey>
52
-
53
- /**
54
- * @category model
55
- * @since 3.10.0
56
- */
57
- export class Pointer {
58
- /**
59
- * @since 3.10.0
60
- */
61
- readonly _tag = "Pointer"
62
- constructor(
63
- readonly path: Path,
64
- readonly actual: unknown,
65
- readonly issue: ParseIssue
66
- ) {}
67
- }
68
-
69
- /**
70
- * Error that occurs when an unexpected key or index is present.
71
- *
72
- * @category model
73
- * @since 3.10.0
74
- */
75
- export class Unexpected {
76
- /**
77
- * @since 3.10.0
78
- */
79
- readonly _tag = "Unexpected"
80
- constructor(
81
- readonly actual: unknown,
82
- /**
83
- * @since 3.10.0
84
- */
85
- readonly message?: string
86
- ) {}
87
- }
88
-
89
- /**
90
- * Error that occurs when a required key or index is missing.
91
- *
92
- * @category model
93
- * @since 3.10.0
94
- */
95
- export class Missing {
96
- /**
97
- * @since 3.10.0
98
- */
99
- readonly _tag = "Missing"
100
- /**
101
- * @since 3.10.0
102
- */
103
- readonly actual = undefined
104
- constructor(
105
- /**
106
- * @since 3.10.0
107
- */
108
- readonly ast: AST.Type,
109
- /**
110
- * @since 3.10.0
111
- */
112
- readonly message?: string
113
- ) {}
114
- }
115
-
116
- /**
117
- * Error that contains multiple issues.
118
- *
119
- * @category model
120
- * @since 3.10.0
121
- */
122
- export class Composite {
123
- /**
124
- * @since 3.10.0
125
- */
126
- readonly _tag = "Composite"
127
- constructor(
128
- readonly ast: AST.AST,
129
- readonly actual: unknown,
130
- readonly issues: SingleOrNonEmpty<ParseIssue>,
131
- readonly output?: unknown
132
- ) {}
133
- }
134
-
135
- /**
136
- * Error that occurs when a refinement has an error.
137
- *
138
- * @category model
139
- * @since 3.10.0
140
- */
141
- export class Refinement {
142
- /**
143
- * @since 3.10.0
144
- */
145
- readonly _tag = "Refinement"
146
- constructor(
147
- readonly ast: AST.Refinement,
148
- readonly actual: unknown,
149
- readonly kind: "From" | "Predicate",
150
- readonly issue: ParseIssue
151
- ) {}
152
- }
153
-
154
- /**
155
- * Error that occurs when a transformation has an error.
156
- *
157
- * @category model
158
- * @since 3.10.0
159
- */
160
- export class Transformation {
161
- /**
162
- * @since 3.10.0
163
- */
164
- readonly _tag = "Transformation"
165
- constructor(
166
- readonly ast: AST.Transformation,
167
- readonly actual: unknown,
168
- readonly kind: "Encoded" | "Transformation" | "Type",
169
- readonly issue: ParseIssue
170
- ) {}
171
- }
172
-
173
- /**
174
- * The `Type` variant of the `ParseIssue` type represents an error that occurs when the `actual` value is not of the expected type.
175
- * The `ast` field specifies the expected type, and the `actual` field contains the value that caused the error.
176
- *
177
- * @category model
178
- * @since 3.10.0
179
- */
180
- export class Type {
181
- /**
182
- * @since 3.10.0
183
- */
184
- readonly _tag = "Type"
185
- constructor(
186
- readonly ast: AST.AST,
187
- readonly actual: unknown,
188
- readonly message?: string
189
- ) {}
190
- }
191
-
192
- /**
193
- * 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`).
194
- *
195
- * @category model
196
- * @since 3.10.0
197
- */
198
- export class Forbidden {
199
- /**
200
- * @since 3.10.0
201
- */
202
- readonly _tag = "Forbidden"
203
- constructor(
204
- readonly ast: AST.AST,
205
- readonly actual: unknown,
206
- readonly message?: string
207
- ) {}
208
- }
209
-
210
- /**
211
- * @category type id
212
- * @since 3.10.0
213
- */
214
- export const ParseErrorTypeId: unique symbol = Symbol.for("effect/Schema/ParseErrorTypeId")
215
-
216
- /**
217
- * @category type id
218
- * @since 3.10.0
219
- */
220
- export type ParseErrorTypeId = typeof ParseErrorTypeId
221
-
222
- /**
223
- * @since 3.10.0
224
- */
225
- export const isParseError = (u: unknown): u is ParseError => Predicate.hasProperty(u, ParseErrorTypeId)
226
-
227
- /**
228
- * @since 3.10.0
229
- */
230
- export class ParseError extends TaggedError("ParseError")<{ readonly issue: ParseIssue }> {
231
- /**
232
- * @since 3.10.0
233
- */
234
- readonly [ParseErrorTypeId] = ParseErrorTypeId
235
-
236
- get message() {
237
- return this.toString()
238
- }
239
- /**
240
- * @since 3.10.0
241
- */
242
- toString() {
243
- return TreeFormatter.formatIssueSync(this.issue)
244
- }
245
- /**
246
- * @since 3.10.0
247
- */
248
- toJSON() {
249
- return {
250
- _id: "ParseError",
251
- message: this.toString()
252
- }
253
- }
254
- /**
255
- * @since 3.10.0
256
- */
257
- [Inspectable.NodeInspectSymbol]() {
258
- return this.toJSON()
259
- }
260
- }
261
-
262
- /**
263
- * @category constructors
264
- * @since 3.10.0
265
- */
266
- export const parseError = (issue: ParseIssue): ParseError => new ParseError({ issue })
267
-
268
- /**
269
- * @category constructors
270
- * @since 3.10.0
271
- */
272
- export const succeed: <A>(a: A) => Either.Either<A, ParseIssue> = Either.right
273
-
274
- /**
275
- * @category constructors
276
- * @since 3.10.0
277
- */
278
- export const fail: (issue: ParseIssue) => Either.Either<never, ParseIssue> = Either.left
279
-
280
- const _try: <A>(options: {
281
- try: LazyArg<A>
282
- catch: (e: unknown) => ParseIssue
283
- }) => Either.Either<A, ParseIssue> = Either.try
284
-
285
- export {
286
- /**
287
- * @category constructors
288
- * @since 3.10.0
289
- */
290
- _try as try
291
- }
292
-
293
- /**
294
- * @category constructors
295
- * @since 3.10.0
296
- */
297
- export const fromOption: {
298
- (onNone: () => ParseIssue): <A>(self: Option.Option<A>) => Either.Either<A, ParseIssue>
299
- <A>(self: Option.Option<A>, onNone: () => ParseIssue): Either.Either<A, ParseIssue>
300
- } = Either.fromOption
301
-
302
- const isEither: <A, E, R>(self: Effect.Effect<A, E, R>) => self is Either.Either<A, E> = Either.isEither as any
303
-
304
- /**
305
- * @category optimisation
306
- * @since 3.10.0
307
- */
308
- export const flatMap: {
309
- <A, B, E1, R1>(
310
- f: (a: A) => Effect.Effect<B, E1, R1>
311
- ): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E1 | E, R1 | R>
312
- <A, E, R, B, E1, R1>(
313
- self: Effect.Effect<A, E, R>,
314
- f: (a: A) => Effect.Effect<B, E1, R1>
315
- ): Effect.Effect<B, E | E1, R | R1>
316
- } = dual(2, <A, E, R, B, E1, R1>(
317
- self: Effect.Effect<A, E, R>,
318
- f: (a: A) => Effect.Effect<B, E1, R1>
319
- ): Effect.Effect<B, E | E1, R | R1> => {
320
- return isEither(self) ?
321
- Either.match(self, { onLeft: Either.left, onRight: f }) :
322
- Effect.flatMap(self, f)
323
- })
324
-
325
- /**
326
- * @category optimisation
327
- * @since 3.10.0
328
- */
329
- export const map: {
330
- <A, B>(f: (a: A) => B): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E, R>
331
- <A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R>
332
- } = dual(2, <A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R> => {
333
- return isEither(self) ?
334
- Either.map(self, f) :
335
- Effect.map(self, f)
336
- })
337
-
338
- /**
339
- * @category optimisation
340
- * @since 3.10.0
341
- */
342
- export const mapError: {
343
- <E, E2>(f: (e: E) => E2): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2, R>
344
- <A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R>
345
- } = dual(2, <A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R> => {
346
- return isEither(self) ?
347
- Either.mapLeft(self, f) :
348
- Effect.mapError(self, f)
349
- })
350
-
351
- // TODO(4.0): remove
352
- /**
353
- * @category optimisation
354
- * @since 3.10.0
355
- */
356
- export const eitherOrUndefined = <A, E, R>(
357
- self: Effect.Effect<A, E, R>
358
- ): Either.Either<A, E> | undefined => {
359
- if (isEither(self)) {
360
- return self
361
- }
362
- }
363
-
364
- /**
365
- * @category optimisation
366
- * @since 3.10.0
367
- */
368
- export const mapBoth: {
369
- <E, E2, A, A2>(
370
- options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
371
- ): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2, E2, R>
372
- <A, E, R, E2, A2>(
373
- self: Effect.Effect<A, E, R>,
374
- options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
375
- ): Effect.Effect<A2, E2, R>
376
- } = dual(2, <A, E, R, E2, A2>(
377
- self: Effect.Effect<A, E, R>,
378
- options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
379
- ): Effect.Effect<A2, E2, R> => {
380
- return isEither(self) ?
381
- Either.mapBoth(self, { onLeft: options.onFailure, onRight: options.onSuccess }) :
382
- Effect.mapBoth(self, options)
383
- })
384
-
385
- /**
386
- * @category optimisation
387
- * @since 3.10.0
388
- */
389
- export const orElse: {
390
- <E, A2, E2, R2>(
391
- f: (e: E) => Effect.Effect<A2, E2, R2>
392
- ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>
393
- <A, E, R, A2, E2, R2>(
394
- self: Effect.Effect<A, E, R>,
395
- f: (e: E) => Effect.Effect<A2, E2, R2>
396
- ): Effect.Effect<A2 | A, E2, R2 | R>
397
- } = dual(2, <A, E, R, A2, E2, R2>(
398
- self: Effect.Effect<A, E, R>,
399
- f: (e: E) => Effect.Effect<A2, E2, R2>
400
- ): Effect.Effect<A2 | A, E2, R2 | R> => {
401
- return isEither(self) ?
402
- Either.match(self, { onLeft: f, onRight: Either.right }) :
403
- Effect.catchAll(self, f)
404
- })
405
-
406
- /**
407
- * @since 3.10.0
408
- */
409
- export type DecodeUnknown<Out, R> = (u: unknown, options?: AST.ParseOptions) => Effect.Effect<Out, ParseIssue, R>
410
-
411
- /**
412
- * @since 3.10.0
413
- */
414
- export type DeclarationDecodeUnknown<Out, R> = (
415
- u: unknown,
416
- options: AST.ParseOptions,
417
- ast: AST.Declaration
418
- ) => Effect.Effect<Out, ParseIssue, R>
419
-
420
- /** @internal */
421
- export const mergeInternalOptions = (
422
- options: InternalOptions | undefined,
423
- overrideOptions: InternalOptions | number | undefined
424
- ): InternalOptions | undefined => {
425
- if (overrideOptions === undefined || Predicate.isNumber(overrideOptions)) {
426
- return options
427
- }
428
- if (options === undefined) {
429
- return overrideOptions
430
- }
431
- return { ...options, ...overrideOptions }
432
- }
433
-
434
- const getEither = (ast: AST.AST, isDecoding: boolean, options?: AST.ParseOptions) => {
435
- const parser = goMemo(ast, isDecoding)
436
- return (u: unknown, overrideOptions?: AST.ParseOptions): Either.Either<any, ParseIssue> =>
437
- parser(u, mergeInternalOptions(options, overrideOptions)) as any
438
- }
439
-
440
- const getSync = (ast: AST.AST, isDecoding: boolean, options?: AST.ParseOptions) => {
441
- const parser = getEither(ast, isDecoding, options)
442
- return (input: unknown, overrideOptions?: AST.ParseOptions) =>
443
- Either.getOrThrowWith(parser(input, overrideOptions), parseError)
444
- }
445
-
446
- /** @internal */
447
- export const getOption = (ast: AST.AST, isDecoding: boolean, options?: AST.ParseOptions) => {
448
- const parser = getEither(ast, isDecoding, options)
449
- return (input: unknown, overrideOptions?: AST.ParseOptions): Option.Option<any> =>
450
- Option.getRight(parser(input, overrideOptions))
451
- }
452
-
453
- const getEffect = <R>(ast: AST.AST, isDecoding: boolean, options?: AST.ParseOptions) => {
454
- const parser = goMemo(ast, isDecoding)
455
- return (input: unknown, overrideOptions?: AST.ParseOptions): Effect.Effect<any, ParseIssue, R> =>
456
- parser(input, { ...mergeInternalOptions(options, overrideOptions), isEffectAllowed: true })
457
- }
458
-
459
- /**
460
- * @throws `ParseError`
461
- * @category decoding
462
- * @since 3.10.0
463
- */
464
- export const decodeUnknownSync = <A, I>(
465
- schema: Schema.Schema<A, I, never>,
466
- options?: AST.ParseOptions
467
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => A => getSync(schema.ast, true, options)
468
-
469
- /**
470
- * @category decoding
471
- * @since 3.10.0
472
- */
473
- export const decodeUnknownOption = <A, I>(
474
- schema: Schema.Schema<A, I, never>,
475
- options?: AST.ParseOptions
476
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Option.Option<A> => getOption(schema.ast, true, options)
477
-
478
- /**
479
- * @category decoding
480
- * @since 3.10.0
481
- */
482
- export const decodeUnknownEither = <A, I>(
483
- schema: Schema.Schema<A, I, never>,
484
- options?: AST.ParseOptions
485
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either<A, ParseIssue> =>
486
- getEither(schema.ast, true, options)
487
-
488
- /**
489
- * @category decoding
490
- * @since 3.10.0
491
- */
492
- export const decodeUnknownPromise = <A, I>(
493
- schema: Schema.Schema<A, I, never>,
494
- options?: AST.ParseOptions
495
- ) => {
496
- const parser = decodeUnknown(schema, options)
497
- return (u: unknown, overrideOptions?: AST.ParseOptions): Promise<A> => Effect.runPromise(parser(u, overrideOptions))
498
- }
499
-
500
- /**
501
- * @category decoding
502
- * @since 3.10.0
503
- */
504
- export const decodeUnknown = <A, I, R>(
505
- schema: Schema.Schema<A, I, R>,
506
- options?: AST.ParseOptions
507
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Effect.Effect<A, ParseIssue, R> =>
508
- getEffect(schema.ast, true, options)
509
-
510
- /**
511
- * @throws `ParseError`
512
- * @category encoding
513
- * @since 3.10.0
514
- */
515
- export const encodeUnknownSync = <A, I>(
516
- schema: Schema.Schema<A, I, never>,
517
- options?: AST.ParseOptions
518
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => I => getSync(schema.ast, false, options)
519
-
520
- /**
521
- * @category encoding
522
- * @since 3.10.0
523
- */
524
- export const encodeUnknownOption = <A, I>(
525
- schema: Schema.Schema<A, I, never>,
526
- options?: AST.ParseOptions
527
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Option.Option<I> => getOption(schema.ast, false, options)
528
-
529
- /**
530
- * @category encoding
531
- * @since 3.10.0
532
- */
533
- export const encodeUnknownEither = <A, I>(
534
- schema: Schema.Schema<A, I, never>,
535
- options?: AST.ParseOptions
536
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either<I, ParseIssue> =>
537
- getEither(schema.ast, false, options)
538
-
539
- /**
540
- * @category encoding
541
- * @since 3.10.0
542
- */
543
- export const encodeUnknownPromise = <A, I>(
544
- schema: Schema.Schema<A, I, never>,
545
- options?: AST.ParseOptions
546
- ) => {
547
- const parser = encodeUnknown(schema, options)
548
- return (u: unknown, overrideOptions?: AST.ParseOptions): Promise<I> => Effect.runPromise(parser(u, overrideOptions))
549
- }
550
-
551
- /**
552
- * @category encoding
553
- * @since 3.10.0
554
- */
555
- export const encodeUnknown = <A, I, R>(
556
- schema: Schema.Schema<A, I, R>,
557
- options?: AST.ParseOptions
558
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Effect.Effect<I, ParseIssue, R> =>
559
- getEffect(schema.ast, false, options)
560
-
561
- /**
562
- * @category decoding
563
- * @since 3.10.0
564
- */
565
- export const decodeSync: <A, I>(
566
- schema: Schema.Schema<A, I, never>,
567
- options?: AST.ParseOptions
568
- ) => (i: I, overrideOptions?: AST.ParseOptions) => A = decodeUnknownSync
569
-
570
- /**
571
- * @category decoding
572
- * @since 3.10.0
573
- */
574
- export const decodeOption: <A, I>(
575
- schema: Schema.Schema<A, I, never>,
576
- options?: AST.ParseOptions
577
- ) => (i: I, overrideOptions?: AST.ParseOptions) => Option.Option<A> = decodeUnknownOption
578
-
579
- /**
580
- * @category decoding
581
- * @since 3.10.0
582
- */
583
- export const decodeEither: <A, I>(
584
- schema: Schema.Schema<A, I, never>,
585
- options?: AST.ParseOptions
586
- ) => (i: I, overrideOptions?: AST.ParseOptions) => Either.Either<A, ParseIssue> = decodeUnknownEither
587
-
588
- /**
589
- * @category decoding
590
- * @since 3.10.0
591
- */
592
- export const decodePromise: <A, I>(
593
- schema: Schema.Schema<A, I, never>,
594
- options?: AST.ParseOptions
595
- ) => (i: I, overrideOptions?: AST.ParseOptions) => Promise<A> = decodeUnknownPromise
596
-
597
- /**
598
- * @category decoding
599
- * @since 3.10.0
600
- */
601
- export const decode: <A, I, R>(
602
- schema: Schema.Schema<A, I, R>,
603
- options?: AST.ParseOptions
604
- ) => (i: I, overrideOptions?: AST.ParseOptions) => Effect.Effect<A, ParseIssue, R> = decodeUnknown
605
-
606
- /**
607
- * @throws `ParseError`
608
- * @category validation
609
- * @since 3.10.0
610
- */
611
- export const validateSync = <A, I, R>(
612
- schema: Schema.Schema<A, I, R>,
613
- options?: AST.ParseOptions
614
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => A => getSync(AST.typeAST(schema.ast), true, options)
615
-
616
- /**
617
- * @category validation
618
- * @since 3.10.0
619
- */
620
- export const validateOption = <A, I, R>(
621
- schema: Schema.Schema<A, I, R>,
622
- options?: AST.ParseOptions
623
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Option.Option<A> =>
624
- getOption(AST.typeAST(schema.ast), true, options)
625
-
626
- /**
627
- * @category validation
628
- * @since 3.10.0
629
- */
630
- export const validateEither = <A, I, R>(
631
- schema: Schema.Schema<A, I, R>,
632
- options?: AST.ParseOptions
633
- ): (u: unknown, overrideOptions?: AST.ParseOptions) => Either.Either<A, ParseIssue> =>
634
- getEither(AST.typeAST(schema.ast), true, options)
635
-
636
- /**
637
- * @category validation
638
- * @since 3.10.0
639
- */
640
- export const validatePromise = <A, I>(
641
- schema: Schema.Schema<A, I, never>,
642
- options?: AST.ParseOptions
643
- ) => {
644
- const parser = validate(schema, options)
645
- return (u: unknown, overrideOptions?: AST.ParseOptions): Promise<A> => Effect.runPromise(parser(u, overrideOptions))
646
- }
647
-
648
- /**
649
- * @category validation
650
- * @since 3.10.0
651
- */
652
- export const validate = <A, I, R>(
653
- schema: Schema.Schema<A, I, R>,
654
- options?: AST.ParseOptions
655
- ): (a: unknown, overrideOptions?: AST.ParseOptions) => Effect.Effect<A, ParseIssue, R> =>
656
- getEffect(AST.typeAST(schema.ast), true, options)
657
-
658
- /**
659
- * By default the option `exact` is set to `true`.
660
- *
661
- * @category validation
662
- * @since 3.10.0
663
- */
664
- export const is = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: AST.ParseOptions) => {
665
- const parser = goMemo(AST.typeAST(schema.ast), true)
666
- return (u: unknown, overrideOptions?: AST.ParseOptions | number): u is A =>
667
- Either.isRight(parser(u, { exact: true, ...mergeInternalOptions(options, overrideOptions) }) as any)
668
- }
669
-
670
- /**
671
- * By default the option `exact` is set to `true`.
672
- *
673
- * @throws `ParseError`
674
- * @category validation
675
- * @since 3.10.0
676
- */
677
- export const asserts = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: AST.ParseOptions) => {
678
- const parser = goMemo(AST.typeAST(schema.ast), true)
679
- return (u: unknown, overrideOptions?: AST.ParseOptions): asserts u is A => {
680
- const result: Either.Either<any, ParseIssue> = parser(u, {
681
- exact: true,
682
- ...mergeInternalOptions(options, overrideOptions)
683
- }) as any
684
- if (Either.isLeft(result)) {
685
- throw parseError(result.left)
686
- }
687
- }
688
- }
689
-
690
- /**
691
- * @category encoding
692
- * @since 3.10.0
693
- */
694
- export const encodeSync: <A, I>(
695
- schema: Schema.Schema<A, I, never>,
696
- options?: AST.ParseOptions
697
- ) => (a: A, overrideOptions?: AST.ParseOptions) => I = encodeUnknownSync
698
-
699
- /**
700
- * @category encoding
701
- * @since 3.10.0
702
- */
703
- export const encodeOption: <A, I>(
704
- schema: Schema.Schema<A, I, never>,
705
- options?: AST.ParseOptions
706
- ) => (input: A, overrideOptions?: AST.ParseOptions) => Option.Option<I> = encodeUnknownOption
707
-
708
- /**
709
- * @category encoding
710
- * @since 3.10.0
711
- */
712
- export const encodeEither: <A, I>(
713
- schema: Schema.Schema<A, I, never>,
714
- options?: AST.ParseOptions
715
- ) => (a: A, overrideOptions?: AST.ParseOptions) => Either.Either<I, ParseIssue> = encodeUnknownEither
716
-
717
- /**
718
- * @category encoding
719
- * @since 3.10.0
720
- */
721
- export const encodePromise: <A, I>(
722
- schema: Schema.Schema<A, I, never>,
723
- options?: AST.ParseOptions
724
- ) => (a: A, overrideOptions?: AST.ParseOptions) => Promise<I> = encodeUnknownPromise
725
-
726
- /**
727
- * @category encoding
728
- * @since 3.10.0
729
- */
730
- export const encode: <A, I, R>(
731
- schema: Schema.Schema<A, I, R>,
732
- options?: AST.ParseOptions
733
- ) => (a: A, overrideOptions?: AST.ParseOptions) => Effect.Effect<I, ParseIssue, R> = encodeUnknown
734
-
735
- interface InternalOptions extends AST.ParseOptions {
736
- readonly isEffectAllowed?: boolean
737
- }
738
-
739
- interface Parser {
740
- (i: any, options?: InternalOptions): Effect.Effect<any, ParseIssue, any>
741
- }
742
-
743
- const decodeMemoMap = globalValue(
744
- Symbol.for("effect/ParseResult/decodeMemoMap"),
745
- () => new WeakMap<AST.AST, Parser>()
746
- )
747
- const encodeMemoMap = globalValue(
748
- Symbol.for("effect/ParseResult/encodeMemoMap"),
749
- () => new WeakMap<AST.AST, Parser>()
750
- )
751
-
752
- const goMemo = (ast: AST.AST, isDecoding: boolean): Parser => {
753
- const memoMap = isDecoding ? decodeMemoMap : encodeMemoMap
754
- const memo = memoMap.get(ast)
755
- if (memo) {
756
- return memo
757
- }
758
- const raw = go(ast, isDecoding)
759
- const parseOptionsAnnotation = AST.getParseOptionsAnnotation(ast)
760
- const parserWithOptions: Parser = Option.isSome(parseOptionsAnnotation)
761
- ? (i, options) => raw(i, mergeInternalOptions(options, parseOptionsAnnotation.value))
762
- : raw
763
- const decodingFallbackAnnotation = AST.getDecodingFallbackAnnotation(ast)
764
- const parser: Parser = isDecoding && Option.isSome(decodingFallbackAnnotation)
765
- ? (i, options) =>
766
- handleForbidden(orElse(parserWithOptions(i, options), decodingFallbackAnnotation.value), ast, i, options)
767
- : parserWithOptions
768
- memoMap.set(ast, parser)
769
- return parser
770
- }
771
-
772
- const getConcurrency = (ast: AST.AST): Concurrency | undefined =>
773
- Option.getOrUndefined(AST.getConcurrencyAnnotation(ast))
774
-
775
- const getBatching = (ast: AST.AST): boolean | "inherit" | undefined =>
776
- Option.getOrUndefined(AST.getBatchingAnnotation(ast))
777
-
778
- const go = (ast: AST.AST, isDecoding: boolean): Parser => {
779
- switch (ast._tag) {
780
- case "Refinement": {
781
- if (isDecoding) {
782
- const from = goMemo(ast.from, true)
783
- return (i, options) => {
784
- options = options ?? AST.defaultParseOption
785
- const allErrors = options?.errors === "all"
786
- const result = flatMap(
787
- orElse(from(i, options), (ef) => {
788
- const issue = new Refinement(ast, i, "From", ef)
789
- if (allErrors && AST.hasStableFilter(ast) && isComposite(ef)) {
790
- return Option.match(
791
- ast.filter(i, options, ast),
792
- {
793
- onNone: () => Either.left<ParseIssue>(issue),
794
- onSome: (ep) => Either.left(new Composite(ast, i, [issue, new Refinement(ast, i, "Predicate", ep)]))
795
- }
796
- )
797
- }
798
- return Either.left(issue)
799
- }),
800
- (a) =>
801
- Option.match(
802
- ast.filter(a, options, ast),
803
- {
804
- onNone: () => Either.right(a),
805
- onSome: (ep) => Either.left(new Refinement(ast, i, "Predicate", ep))
806
- }
807
- )
808
- )
809
- return handleForbidden(result, ast, i, options)
810
- }
811
- } else {
812
- const from = goMemo(AST.typeAST(ast), true)
813
- const to = goMemo(dropRightRefinement(ast.from), false)
814
- return (i, options) => handleForbidden(flatMap(from(i, options), (a) => to(a, options)), ast, i, options)
815
- }
816
- }
817
- case "Transformation": {
818
- const transform = getFinalTransformation(ast.transformation, isDecoding)
819
- const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false)
820
- const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false)
821
- return (i, options) =>
822
- handleForbidden(
823
- flatMap(
824
- mapError(
825
- from(i, options),
826
- (e) => new Transformation(ast, i, isDecoding ? "Encoded" : "Type", e)
827
- ),
828
- (a) =>
829
- flatMap(
830
- mapError(
831
- transform(a, options ?? AST.defaultParseOption, ast, i),
832
- (e) => new Transformation(ast, i, "Transformation", e)
833
- ),
834
- (i2) =>
835
- mapError(
836
- to(i2, options),
837
- (e) => new Transformation(ast, i, isDecoding ? "Type" : "Encoded", e)
838
- )
839
- )
840
- ),
841
- ast,
842
- i,
843
- options
844
- )
845
- }
846
- case "Declaration": {
847
- const parse = isDecoding
848
- ? ast.decodeUnknown(...ast.typeParameters)
849
- : ast.encodeUnknown(...ast.typeParameters)
850
- return (i, options) => handleForbidden(parse(i, options ?? AST.defaultParseOption, ast), ast, i, options)
851
- }
852
- case "Literal":
853
- return fromRefinement(ast, (u): u is typeof ast.literal => u === ast.literal)
854
- case "UniqueSymbol":
855
- return fromRefinement(ast, (u): u is typeof ast.symbol => u === ast.symbol)
856
- case "UndefinedKeyword":
857
- return fromRefinement(ast, Predicate.isUndefined)
858
- case "NeverKeyword":
859
- return fromRefinement(ast, Predicate.isNever)
860
- case "UnknownKeyword":
861
- case "AnyKeyword":
862
- case "VoidKeyword":
863
- return Either.right
864
- case "StringKeyword":
865
- return fromRefinement(ast, Predicate.isString)
866
- case "NumberKeyword":
867
- return fromRefinement(ast, Predicate.isNumber)
868
- case "BooleanKeyword":
869
- return fromRefinement(ast, Predicate.isBoolean)
870
- case "BigIntKeyword":
871
- return fromRefinement(ast, Predicate.isBigInt)
872
- case "SymbolKeyword":
873
- return fromRefinement(ast, Predicate.isSymbol)
874
- case "ObjectKeyword":
875
- return fromRefinement(ast, Predicate.isObject)
876
- case "Enums":
877
- return fromRefinement(ast, (u): u is any => ast.enums.some(([_, value]) => value === u))
878
- case "TemplateLiteral": {
879
- const regex = AST.getTemplateLiteralRegExp(ast)
880
- return fromRefinement(ast, (u): u is any => Predicate.isString(u) && regex.test(u))
881
- }
882
- case "TupleType": {
883
- const elements = ast.elements.map((e) => goMemo(e.type, isDecoding))
884
- const rest = ast.rest.map((annotatedAST) => goMemo(annotatedAST.type, isDecoding))
885
- let requiredTypes: Array<AST.Type> = ast.elements.filter((e) => !e.isOptional)
886
- if (ast.rest.length > 0) {
887
- requiredTypes = requiredTypes.concat(ast.rest.slice(1))
888
- }
889
- const requiredLen = requiredTypes.length
890
- const expectedIndexes = ast.elements.length > 0 ? ast.elements.map((_, i) => i).join(" | ") : "never"
891
- const concurrency = getConcurrency(ast)
892
- const batching = getBatching(ast)
893
- return (input: unknown, options) => {
894
- if (!Arr.isArray(input)) {
895
- return Either.left(new Type(ast, input))
896
- }
897
- const allErrors = options?.errors === "all"
898
- const es: Array<[number, ParseIssue]> = []
899
- let stepKey = 0
900
- const output: Array<[number, any]> = []
901
- // ---------------------------------------------
902
- // handle missing indexes
903
- // ---------------------------------------------
904
- const len = input.length
905
- for (let i = len; i <= requiredLen - 1; i++) {
906
- const e = new Pointer(i, input, new Missing(requiredTypes[i - len]))
907
- if (allErrors) {
908
- es.push([stepKey++, e])
909
- continue
910
- } else {
911
- return Either.left(new Composite(ast, input, e, output))
912
- }
913
- }
914
-
915
- // ---------------------------------------------
916
- // handle excess indexes
917
- // ---------------------------------------------
918
- if (ast.rest.length === 0) {
919
- for (let i = ast.elements.length; i <= len - 1; i++) {
920
- const e = new Pointer(i, input, new Unexpected(input[i], `is unexpected, expected: ${expectedIndexes}`))
921
- if (allErrors) {
922
- es.push([stepKey++, e])
923
- continue
924
- } else {
925
- return Either.left(new Composite(ast, input, e, output))
926
- }
927
- }
928
- }
929
-
930
- let i = 0
931
- type State = {
932
- es: typeof es
933
- output: typeof output
934
- }
935
- let queue:
936
- | Array<(_: State) => Effect.Effect<void, ParseIssue, any>>
937
- | undefined = undefined
938
-
939
- // ---------------------------------------------
940
- // handle elements
941
- // ---------------------------------------------
942
- for (; i < elements.length; i++) {
943
- if (len < i + 1) {
944
- if (ast.elements[i].isOptional) {
945
- // the input element is missing
946
- continue
947
- }
948
- } else {
949
- const parser = elements[i]
950
- const te = parser(input[i], options)
951
- if (isEither(te)) {
952
- if (Either.isLeft(te)) {
953
- // the input element is present but is not valid
954
- const e = new Pointer(i, input, te.left)
955
- if (allErrors) {
956
- es.push([stepKey++, e])
957
- continue
958
- } else {
959
- return Either.left(new Composite(ast, input, e, sortByIndex(output)))
960
- }
961
- }
962
- output.push([stepKey++, te.right])
963
- } else {
964
- const nk = stepKey++
965
- const index = i
966
- if (!queue) {
967
- queue = []
968
- }
969
- queue.push(({ es, output }: State) =>
970
- Effect.flatMap(Effect.either(te), (t) => {
971
- if (Either.isLeft(t)) {
972
- // the input element is present but is not valid
973
- const e = new Pointer(index, input, t.left)
974
- if (allErrors) {
975
- es.push([nk, e])
976
- return Effect.void
977
- } else {
978
- return Either.left(new Composite(ast, input, e, sortByIndex(output)))
979
- }
980
- }
981
- output.push([nk, t.right])
982
- return Effect.void
983
- })
984
- )
985
- }
986
- }
987
- }
988
- // ---------------------------------------------
989
- // handle rest element
990
- // ---------------------------------------------
991
- if (Arr.isNonEmptyReadonlyArray(rest)) {
992
- const [head, ...tail] = rest
993
- for (; i < len - tail.length; i++) {
994
- const te = head(input[i], options)
995
- if (isEither(te)) {
996
- if (Either.isLeft(te)) {
997
- const e = new Pointer(i, input, te.left)
998
- if (allErrors) {
999
- es.push([stepKey++, e])
1000
- continue
1001
- } else {
1002
- return Either.left(new Composite(ast, input, e, sortByIndex(output)))
1003
- }
1004
- } else {
1005
- output.push([stepKey++, te.right])
1006
- }
1007
- } else {
1008
- const nk = stepKey++
1009
- const index = i
1010
- if (!queue) {
1011
- queue = []
1012
- }
1013
- queue.push(
1014
- ({ es, output }: State) =>
1015
- Effect.flatMap(Effect.either(te), (t) => {
1016
- if (Either.isLeft(t)) {
1017
- const e = new Pointer(index, input, t.left)
1018
- if (allErrors) {
1019
- es.push([nk, e])
1020
- return Effect.void
1021
- } else {
1022
- return Either.left(new Composite(ast, input, e, sortByIndex(output)))
1023
- }
1024
- } else {
1025
- output.push([nk, t.right])
1026
- return Effect.void
1027
- }
1028
- })
1029
- )
1030
- }
1031
- }
1032
- // ---------------------------------------------
1033
- // handle post rest elements
1034
- // ---------------------------------------------
1035
- for (let j = 0; j < tail.length; j++) {
1036
- i += j
1037
- if (len < i + 1) {
1038
- continue
1039
- } else {
1040
- const te = tail[j](input[i], options)
1041
- if (isEither(te)) {
1042
- if (Either.isLeft(te)) {
1043
- // the input element is present but is not valid
1044
- const e = new Pointer(i, input, te.left)
1045
- if (allErrors) {
1046
- es.push([stepKey++, e])
1047
- continue
1048
- } else {
1049
- return Either.left(new Composite(ast, input, e, sortByIndex(output)))
1050
- }
1051
- }
1052
- output.push([stepKey++, te.right])
1053
- } else {
1054
- const nk = stepKey++
1055
- const index = i
1056
- if (!queue) {
1057
- queue = []
1058
- }
1059
- queue.push(
1060
- ({ es, output }: State) =>
1061
- Effect.flatMap(Effect.either(te), (t) => {
1062
- if (Either.isLeft(t)) {
1063
- // the input element is present but is not valid
1064
- const e = new Pointer(index, input, t.left)
1065
- if (allErrors) {
1066
- es.push([nk, e])
1067
- return Effect.void
1068
- } else {
1069
- return Either.left(new Composite(ast, input, e, sortByIndex(output)))
1070
- }
1071
- }
1072
- output.push([nk, t.right])
1073
- return Effect.void
1074
- })
1075
- )
1076
- }
1077
- }
1078
- }
1079
- }
1080
-
1081
- // ---------------------------------------------
1082
- // compute result
1083
- // ---------------------------------------------
1084
- const computeResult = ({ es, output }: State) =>
1085
- Arr.isNonEmptyArray(es) ?
1086
- Either.left(new Composite(ast, input, sortByIndex(es), sortByIndex(output))) :
1087
- Either.right(sortByIndex(output))
1088
- if (queue && queue.length > 0) {
1089
- const cqueue = queue
1090
- return Effect.suspend(() => {
1091
- const state: State = {
1092
- es: Arr.copy(es),
1093
- output: Arr.copy(output)
1094
- }
1095
- return Effect.flatMap(
1096
- Effect.forEach(cqueue, (f) => f(state), { concurrency, batching, discard: true }),
1097
- () => computeResult(state)
1098
- )
1099
- })
1100
- }
1101
- return computeResult({ output, es })
1102
- }
1103
- }
1104
- case "TypeLiteral": {
1105
- if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) {
1106
- return fromRefinement(ast, Predicate.isNotNullable)
1107
- }
1108
-
1109
- const propertySignatures: Array<readonly [Parser, AST.PropertySignature]> = []
1110
- const expectedKeysMap: Record<PropertyKey, null> = {}
1111
- const expectedKeys: Array<PropertyKey> = []
1112
- for (const ps of ast.propertySignatures) {
1113
- propertySignatures.push([goMemo(ps.type, isDecoding), ps])
1114
- expectedKeysMap[ps.name] = null
1115
- expectedKeys.push(ps.name)
1116
- }
1117
-
1118
- const indexSignatures = ast.indexSignatures.map((is) =>
1119
- [
1120
- goMemo(is.parameter, isDecoding),
1121
- goMemo(is.type, isDecoding),
1122
- is.parameter
1123
- ] as const
1124
- )
1125
- const expectedAST = AST.Union.make(
1126
- ast.indexSignatures.map((is): AST.AST => is.parameter).concat(
1127
- expectedKeys.map((key) => Predicate.isSymbol(key) ? new AST.UniqueSymbol(key) : new AST.Literal(key))
1128
- )
1129
- )
1130
- const expected = goMemo(expectedAST, isDecoding)
1131
- const concurrency = getConcurrency(ast)
1132
- const batching = getBatching(ast)
1133
- return (input: unknown, options) => {
1134
- if (!Predicate.isRecord(input)) {
1135
- return Either.left(new Type(ast, input))
1136
- }
1137
- const allErrors = options?.errors === "all"
1138
- const es: Array<[number, ParseIssue]> = []
1139
- let stepKey = 0
1140
-
1141
- // ---------------------------------------------
1142
- // handle excess properties
1143
- // ---------------------------------------------
1144
- const onExcessPropertyError = options?.onExcessProperty === "error"
1145
- const onExcessPropertyPreserve = options?.onExcessProperty === "preserve"
1146
- const output: Record<PropertyKey, unknown> = {}
1147
- let inputKeys: Array<PropertyKey> | undefined
1148
- if (onExcessPropertyError || onExcessPropertyPreserve) {
1149
- inputKeys = Reflect.ownKeys(input)
1150
- for (const key of inputKeys) {
1151
- const te = expected(key, options)
1152
- if (isEither(te) && Either.isLeft(te)) {
1153
- // key is unexpected
1154
- if (onExcessPropertyError) {
1155
- const e = new Pointer(
1156
- key,
1157
- input,
1158
- new Unexpected(input[key], `is unexpected, expected: ${String(expectedAST)}`)
1159
- )
1160
- if (allErrors) {
1161
- es.push([stepKey++, e])
1162
- continue
1163
- } else {
1164
- return Either.left(new Composite(ast, input, e, output))
1165
- }
1166
- } else {
1167
- // preserve key
1168
- output[key] = input[key]
1169
- }
1170
- }
1171
- }
1172
- }
1173
-
1174
- // ---------------------------------------------
1175
- // handle property signatures
1176
- // ---------------------------------------------
1177
- type State = {
1178
- es: typeof es
1179
- output: typeof output
1180
- }
1181
- let queue:
1182
- | Array<(state: State) => Effect.Effect<void, ParseIssue, any>>
1183
- | undefined = undefined
1184
-
1185
- const isExact = options?.exact === true
1186
- for (let i = 0; i < propertySignatures.length; i++) {
1187
- const ps = propertySignatures[i][1]
1188
- const name = ps.name
1189
- const hasKey = Object.prototype.hasOwnProperty.call(input, name)
1190
- if (!hasKey) {
1191
- if (ps.isOptional) {
1192
- continue
1193
- } else if (isExact) {
1194
- const e = new Pointer(name, input, new Missing(ps))
1195
- if (allErrors) {
1196
- es.push([stepKey++, e])
1197
- continue
1198
- } else {
1199
- return Either.left(new Composite(ast, input, e, output))
1200
- }
1201
- }
1202
- }
1203
- const parser = propertySignatures[i][0]
1204
- const te = parser(input[name], options)
1205
- if (isEither(te)) {
1206
- if (Either.isLeft(te)) {
1207
- const e = new Pointer(name, input, hasKey ? te.left : new Missing(ps))
1208
- if (allErrors) {
1209
- es.push([stepKey++, e])
1210
- continue
1211
- } else {
1212
- return Either.left(new Composite(ast, input, e, output))
1213
- }
1214
- }
1215
- output[name] = te.right
1216
- } else {
1217
- const nk = stepKey++
1218
- const index = name
1219
- if (!queue) {
1220
- queue = []
1221
- }
1222
- queue.push(
1223
- ({ es, output }: State) =>
1224
- Effect.flatMap(Effect.either(te), (t) => {
1225
- if (Either.isLeft(t)) {
1226
- const e = new Pointer(index, input, hasKey ? t.left : new Missing(ps))
1227
- if (allErrors) {
1228
- es.push([nk, e])
1229
- return Effect.void
1230
- } else {
1231
- return Either.left(new Composite(ast, input, e, output))
1232
- }
1233
- }
1234
- output[index] = t.right
1235
- return Effect.void
1236
- })
1237
- )
1238
- }
1239
- }
1240
-
1241
- // ---------------------------------------------
1242
- // handle index signatures
1243
- // ---------------------------------------------
1244
- for (let i = 0; i < indexSignatures.length; i++) {
1245
- const indexSignature = indexSignatures[i]
1246
- const parameter = indexSignature[0]
1247
- const type = indexSignature[1]
1248
- const keys = util_.getKeysForIndexSignature(input, indexSignature[2])
1249
- for (const key of keys) {
1250
- // ---------------------------------------------
1251
- // handle keys
1252
- // ---------------------------------------------
1253
- const keu = parameter(key, options)
1254
- if (isEither(keu) && Either.isRight(keu)) {
1255
- // ---------------------------------------------
1256
- // handle values
1257
- // ---------------------------------------------
1258
- const vpr = type(input[key], options)
1259
- if (isEither(vpr)) {
1260
- if (Either.isLeft(vpr)) {
1261
- const e = new Pointer(key, input, vpr.left)
1262
- if (allErrors) {
1263
- es.push([stepKey++, e])
1264
- continue
1265
- } else {
1266
- return Either.left(new Composite(ast, input, e, output))
1267
- }
1268
- } else {
1269
- if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
1270
- output[key] = vpr.right
1271
- }
1272
- }
1273
- } else {
1274
- const nk = stepKey++
1275
- const index = key
1276
- if (!queue) {
1277
- queue = []
1278
- }
1279
- queue.push(
1280
- ({ es, output }: State) =>
1281
- Effect.flatMap(
1282
- Effect.either(vpr),
1283
- (tv) => {
1284
- if (Either.isLeft(tv)) {
1285
- const e = new Pointer(index, input, tv.left)
1286
- if (allErrors) {
1287
- es.push([nk, e])
1288
- return Effect.void
1289
- } else {
1290
- return Either.left(new Composite(ast, input, e, output))
1291
- }
1292
- } else {
1293
- if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
1294
- output[key] = tv.right
1295
- }
1296
- return Effect.void
1297
- }
1298
- }
1299
- )
1300
- )
1301
- }
1302
- }
1303
- }
1304
- }
1305
- // ---------------------------------------------
1306
- // compute result
1307
- // ---------------------------------------------
1308
- const computeResult = ({ es, output }: State) => {
1309
- if (Arr.isNonEmptyArray(es)) {
1310
- return Either.left(new Composite(ast, input, sortByIndex(es), output))
1311
- }
1312
- if (options?.propertyOrder === "original") {
1313
- // preserve input keys order
1314
- const keys = inputKeys || Reflect.ownKeys(input)
1315
- for (const name of expectedKeys) {
1316
- if (keys.indexOf(name) === -1) {
1317
- keys.push(name)
1318
- }
1319
- }
1320
- const out: any = {}
1321
- for (const key of keys) {
1322
- if (Object.prototype.hasOwnProperty.call(output, key)) {
1323
- out[key] = output[key]
1324
- }
1325
- }
1326
- return Either.right(out)
1327
- }
1328
- return Either.right(output)
1329
- }
1330
- if (queue && queue.length > 0) {
1331
- const cqueue = queue
1332
- return Effect.suspend(() => {
1333
- const state: State = {
1334
- es: Arr.copy(es),
1335
- output: Object.assign({}, output)
1336
- }
1337
- return Effect.flatMap(
1338
- Effect.forEach(cqueue, (f) => f(state), { concurrency, batching, discard: true }),
1339
- () => computeResult(state)
1340
- )
1341
- })
1342
- }
1343
- return computeResult({ es, output })
1344
- }
1345
- }
1346
- case "Union": {
1347
- const searchTree = getSearchTree(ast.types, isDecoding)
1348
- const ownKeys = Reflect.ownKeys(searchTree.keys)
1349
- const ownKeysLen = ownKeys.length
1350
- const astTypesLen = ast.types.length
1351
- const map = new Map<any, Parser>()
1352
- for (let i = 0; i < astTypesLen; i++) {
1353
- map.set(ast.types[i], goMemo(ast.types[i], isDecoding))
1354
- }
1355
- const concurrency = getConcurrency(ast) ?? 1
1356
- const batching = getBatching(ast)
1357
- return (input, options) => {
1358
- const es: Array<[number, ParseIssue]> = []
1359
- let stepKey = 0
1360
- let candidates: Array<AST.AST> = []
1361
- if (ownKeysLen > 0) {
1362
- if (Predicate.isRecordOrArray(input)) {
1363
- for (let i = 0; i < ownKeysLen; i++) {
1364
- const name = ownKeys[i]
1365
- const buckets = searchTree.keys[name].buckets
1366
- // for each property that should contain a literal, check if the input contains that property
1367
- if (Object.prototype.hasOwnProperty.call(input, name)) {
1368
- const literal = String(input[name])
1369
- // check that the value obtained from the input for the property corresponds to an existing bucket
1370
- if (Object.prototype.hasOwnProperty.call(buckets, literal)) {
1371
- // retrive the minimal set of candidates for decoding
1372
- candidates = candidates.concat(buckets[literal])
1373
- } else {
1374
- const { candidates, literals } = searchTree.keys[name]
1375
- const literalsUnion = AST.Union.make(literals)
1376
- const errorAst = candidates.length === astTypesLen
1377
- ? new AST.TypeLiteral([new AST.PropertySignature(name, literalsUnion, false, true)], [])
1378
- : AST.Union.make(candidates)
1379
- es.push([
1380
- stepKey++,
1381
- new Composite(errorAst, input, new Pointer(name, input, new Type(literalsUnion, input[name])))
1382
- ])
1383
- }
1384
- } else {
1385
- const { candidates, literals } = searchTree.keys[name]
1386
- const fakePropertySignature = new AST.PropertySignature(name, AST.Union.make(literals), false, true)
1387
- const errorAst = candidates.length === astTypesLen
1388
- ? new AST.TypeLiteral([fakePropertySignature], [])
1389
- : AST.Union.make(candidates)
1390
- es.push([
1391
- stepKey++,
1392
- new Composite(errorAst, input, new Pointer(name, input, new Missing(fakePropertySignature)))
1393
- ])
1394
- }
1395
- }
1396
- } else {
1397
- const errorAst = searchTree.candidates.length === astTypesLen
1398
- ? ast
1399
- : AST.Union.make(searchTree.candidates)
1400
- es.push([stepKey++, new Type(errorAst, input)])
1401
- }
1402
- }
1403
- if (searchTree.otherwise.length > 0) {
1404
- candidates = candidates.concat(searchTree.otherwise)
1405
- }
1406
-
1407
- let queue:
1408
- | Array<(state: State) => Effect.Effect<unknown, ParseIssue, any>>
1409
- | undefined = undefined
1410
-
1411
- type State = {
1412
- finalResult?: any
1413
- es: typeof es
1414
- }
1415
-
1416
- for (let i = 0; i < candidates.length; i++) {
1417
- const candidate = candidates[i]
1418
- const pr = map.get(candidate)!(input, options)
1419
- // the members of a union are ordered based on which one should be decoded first,
1420
- // therefore if one member has added a task, all subsequent members must
1421
- // also add a task to the queue even if they are synchronous
1422
- if (isEither(pr) && (!queue || queue.length === 0)) {
1423
- if (Either.isRight(pr)) {
1424
- return pr
1425
- } else {
1426
- es.push([stepKey++, pr.left])
1427
- }
1428
- } else {
1429
- const nk = stepKey++
1430
- if (!queue) {
1431
- queue = []
1432
- }
1433
- queue.push(
1434
- (state) =>
1435
- Effect.suspend(() => {
1436
- if ("finalResult" in state) {
1437
- return Effect.void
1438
- } else {
1439
- return Effect.flatMap(Effect.either(pr), (t) => {
1440
- if (Either.isRight(t)) {
1441
- state.finalResult = t
1442
- } else {
1443
- state.es.push([nk, t.left])
1444
- }
1445
- return Effect.void
1446
- })
1447
- }
1448
- })
1449
- )
1450
- }
1451
- }
1452
-
1453
- // ---------------------------------------------
1454
- // compute result
1455
- // ---------------------------------------------
1456
- const computeResult = (es: State["es"]) =>
1457
- Arr.isNonEmptyArray(es) ?
1458
- es.length === 1 && es[0][1]._tag === "Type" ?
1459
- Either.left(es[0][1]) :
1460
- Either.left(new Composite(ast, input, sortByIndex(es))) :
1461
- // this should never happen
1462
- Either.left(new Type(ast, input))
1463
-
1464
- if (queue && queue.length > 0) {
1465
- const cqueue = queue
1466
- return Effect.suspend(() => {
1467
- const state: State = { es: Arr.copy(es) }
1468
- return Effect.flatMap(
1469
- Effect.forEach(cqueue, (f) => f(state), { concurrency, batching, discard: true }),
1470
- () => {
1471
- if ("finalResult" in state) {
1472
- return state.finalResult
1473
- }
1474
- return computeResult(state.es)
1475
- }
1476
- )
1477
- })
1478
- }
1479
- return computeResult(es)
1480
- }
1481
- }
1482
- case "Suspend": {
1483
- const get = util_.memoizeThunk(() => goMemo(ast.f(), isDecoding))
1484
- return (a, options) => get()(a, options)
1485
- }
1486
- }
1487
- }
1488
-
1489
- const fromRefinement = <A>(ast: AST.AST, refinement: (u: unknown) => u is A): Parser => (u) =>
1490
- refinement(u) ? Either.right(u) : Either.left(new Type(ast, u))
1491
-
1492
- /** @internal */
1493
- export const getLiterals = (
1494
- ast: AST.AST,
1495
- isDecoding: boolean
1496
- ): ReadonlyArray<[PropertyKey, AST.Literal]> => {
1497
- switch (ast._tag) {
1498
- case "Declaration": {
1499
- const annotation = AST.getSurrogateAnnotation(ast)
1500
- if (Option.isSome(annotation)) {
1501
- return getLiterals(annotation.value, isDecoding)
1502
- }
1503
- break
1504
- }
1505
- case "TypeLiteral": {
1506
- const out: Array<[PropertyKey, AST.Literal]> = []
1507
- for (let i = 0; i < ast.propertySignatures.length; i++) {
1508
- const propertySignature = ast.propertySignatures[i]
1509
- const type = isDecoding ? AST.encodedAST(propertySignature.type) : AST.typeAST(propertySignature.type)
1510
- if (AST.isLiteral(type) && !propertySignature.isOptional) {
1511
- out.push([propertySignature.name, type])
1512
- }
1513
- }
1514
- return out
1515
- }
1516
- case "TupleType": {
1517
- const out: Array<[PropertyKey, AST.Literal]> = []
1518
- for (let i = 0; i < ast.elements.length; i++) {
1519
- const element = ast.elements[i]
1520
- const type = isDecoding ? AST.encodedAST(element.type) : AST.typeAST(element.type)
1521
- if (AST.isLiteral(type) && !element.isOptional) {
1522
- out.push([i, type])
1523
- }
1524
- }
1525
- return out
1526
- }
1527
- case "Refinement":
1528
- return getLiterals(ast.from, isDecoding)
1529
- case "Suspend":
1530
- return getLiterals(ast.f(), isDecoding)
1531
- case "Transformation":
1532
- return getLiterals(isDecoding ? ast.from : ast.to, isDecoding)
1533
- }
1534
- return []
1535
- }
1536
-
1537
- /**
1538
- * The purpose of the algorithm is to narrow down the pool of possible
1539
- * candidates for decoding as much as possible.
1540
- *
1541
- * This function separates the schemas into two groups, `keys` and `otherwise`:
1542
- *
1543
- * - `keys`: the schema has at least one property with a literal value
1544
- * - `otherwise`: the schema has no properties with a literal value
1545
- *
1546
- * If a schema has at least one property with a literal value, so it ends up in
1547
- * `keys`, first a namespace is created for the name of the property containing
1548
- * the literal, and then within this namespace a "bucket" is created for the
1549
- * literal value in which to store all the schemas that have the same property
1550
- * and literal value.
1551
- *
1552
- * @internal
1553
- */
1554
- export const getSearchTree = (
1555
- members: ReadonlyArray<AST.AST>,
1556
- isDecoding: boolean
1557
- ): {
1558
- keys: {
1559
- readonly [key: PropertyKey]: {
1560
- buckets: { [literal: string]: ReadonlyArray<AST.AST> }
1561
- literals: ReadonlyArray<AST.Literal> // this is for error messages
1562
- candidates: ReadonlyArray<AST.AST>
1563
- }
1564
- }
1565
- otherwise: ReadonlyArray<AST.AST>
1566
- candidates: ReadonlyArray<AST.AST>
1567
- } => {
1568
- const keys: {
1569
- [key: PropertyKey]: {
1570
- buckets: { [literal: string]: Array<AST.AST> }
1571
- literals: Array<AST.Literal>
1572
- candidates: Array<AST.AST>
1573
- }
1574
- } = {}
1575
- const otherwise: Array<AST.AST> = []
1576
- const candidates: Array<AST.AST> = []
1577
- for (let i = 0; i < members.length; i++) {
1578
- const member = members[i]
1579
- const tags = getLiterals(member, isDecoding)
1580
- if (tags.length > 0) {
1581
- candidates.push(member)
1582
- for (let j = 0; j < tags.length; j++) {
1583
- const [key, literal] = tags[j]
1584
- const hash = String(literal.literal)
1585
- keys[key] = keys[key] || { buckets: {}, literals: [], candidates: [] }
1586
- const buckets = keys[key].buckets
1587
- if (Object.prototype.hasOwnProperty.call(buckets, hash)) {
1588
- if (j < tags.length - 1) {
1589
- continue
1590
- }
1591
- buckets[hash].push(member)
1592
- keys[key].literals.push(literal)
1593
- keys[key].candidates.push(member)
1594
- } else {
1595
- buckets[hash] = [member]
1596
- keys[key].literals.push(literal)
1597
- keys[key].candidates.push(member)
1598
- break
1599
- }
1600
- }
1601
- } else {
1602
- otherwise.push(member)
1603
- }
1604
- }
1605
- return { keys, otherwise, candidates }
1606
- }
1607
-
1608
- const dropRightRefinement = (ast: AST.AST): AST.AST => AST.isRefinement(ast) ? dropRightRefinement(ast.from) : ast
1609
-
1610
- const handleForbidden = <A, R>(
1611
- effect: Effect.Effect<A, ParseIssue, R>,
1612
- ast: AST.AST,
1613
- actual: unknown,
1614
- options: InternalOptions | undefined
1615
- ): Effect.Effect<A, ParseIssue, R> => {
1616
- // If effects are allowed, return the original effect
1617
- if (options?.isEffectAllowed === true) {
1618
- return effect
1619
- }
1620
-
1621
- // If the effect is already an Either, return it directly
1622
- if (isEither(effect)) {
1623
- return effect
1624
- }
1625
-
1626
- // Otherwise, attempt to execute the effect synchronously
1627
- const scheduler = new Scheduler.SyncScheduler()
1628
- const fiber = Effect.runFork(effect as Effect.Effect<A, ParseIssue>, { scheduler })
1629
- scheduler.flush()
1630
- const exit = fiber.unsafePoll()
1631
-
1632
- if (exit) {
1633
- if (Exit.isSuccess(exit)) {
1634
- // If the effect successfully resolves, wrap the value in a Right
1635
- return Either.right(exit.value)
1636
- }
1637
- const cause = exit.cause
1638
- if (Cause.isFailType(cause)) {
1639
- // The effect executed synchronously but failed due to a ParseIssue
1640
- return Either.left(cause.error)
1641
- }
1642
- // The effect executed synchronously but failed due to a defect (e.g., a missing dependency)
1643
- return Either.left(new Forbidden(ast, actual, Cause.pretty(cause)))
1644
- }
1645
-
1646
- // The effect could not be resolved synchronously, meaning it performs async work
1647
- return Either.left(
1648
- new Forbidden(
1649
- ast,
1650
- actual,
1651
- "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"
1652
- )
1653
- )
1654
- }
1655
-
1656
- const compare = ([a]: [number, ...Array<unknown>], [b]: [number, ...Array<unknown>]) => a > b ? 1 : a < b ? -1 : 0
1657
-
1658
- function sortByIndex<T>(
1659
- es: Arr.NonEmptyArray<[number, T]>
1660
- ): Arr.NonEmptyArray<T>
1661
- function sortByIndex<T>(es: Array<[number, T]>): Array<T>
1662
- function sortByIndex(es: Array<[number, any]>) {
1663
- return es.sort(compare).map((t) => t[1])
1664
- }
1665
-
1666
- // -------------------------------------------------------------------------------------
1667
- // transformations interpreter
1668
- // -------------------------------------------------------------------------------------
1669
-
1670
- /** @internal */
1671
- export const getFinalTransformation = (
1672
- transformation: AST.TransformationKind,
1673
- isDecoding: boolean
1674
- ): (
1675
- fromA: any,
1676
- options: AST.ParseOptions,
1677
- self: AST.Transformation,
1678
- fromI: any
1679
- ) => Effect.Effect<any, ParseIssue, any> => {
1680
- switch (transformation._tag) {
1681
- case "FinalTransformation":
1682
- return isDecoding ? transformation.decode : transformation.encode
1683
- case "ComposeTransformation":
1684
- return Either.right
1685
- case "TypeLiteralTransformation":
1686
- return (input) => {
1687
- let out: Effect.Effect<any, ParseIssue, any> = Either.right(input)
1688
-
1689
- // ---------------------------------------------
1690
- // handle property signature transformations
1691
- // ---------------------------------------------
1692
- for (const pst of transformation.propertySignatureTransformations) {
1693
- const [from, to] = isDecoding ?
1694
- [pst.from, pst.to] :
1695
- [pst.to, pst.from]
1696
- const transformation = isDecoding ? pst.decode : pst.encode
1697
- const f = (input: any) => {
1698
- const o = transformation(
1699
- Object.prototype.hasOwnProperty.call(input, from) ?
1700
- Option.some(input[from]) :
1701
- Option.none()
1702
- )
1703
- delete input[from]
1704
- if (Option.isSome(o)) {
1705
- input[to] = o.value
1706
- }
1707
- return input
1708
- }
1709
- out = map(out, f)
1710
- }
1711
- return out
1712
- }
1713
- }
1714
- }
1715
-
1716
- // ----------------
1717
- // Formatters
1718
- // ----------------
1719
-
1720
- interface Forest<A> extends ReadonlyArray<Tree<A>> {}
1721
-
1722
- interface Tree<A> {
1723
- readonly value: A
1724
- readonly forest: Forest<A>
1725
- }
1726
-
1727
- const makeTree = <A>(value: A, forest: Forest<A> = []): Tree<A> => ({
1728
- value,
1729
- forest
1730
- })
1731
-
1732
- /**
1733
- * @category formatting
1734
- * @since 3.10.0
1735
- */
1736
- export interface ParseResultFormatter<A> {
1737
- readonly formatIssue: (issue: ParseIssue) => Effect.Effect<A>
1738
- readonly formatIssueSync: (issue: ParseIssue) => A
1739
- readonly formatError: (error: ParseError) => Effect.Effect<A>
1740
- readonly formatErrorSync: (error: ParseError) => A
1741
- }
1742
-
1743
- /**
1744
- * @category formatting
1745
- * @since 3.10.0
1746
- */
1747
- export const TreeFormatter: ParseResultFormatter<string> = {
1748
- formatIssue: (issue) => map(formatTree(issue), drawTree),
1749
- formatIssueSync: (issue) => {
1750
- const e = TreeFormatter.formatIssue(issue)
1751
- return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e)
1752
- },
1753
- formatError: (error) => TreeFormatter.formatIssue(error.issue),
1754
- formatErrorSync: (error) => TreeFormatter.formatIssueSync(error.issue)
1755
- }
1756
-
1757
- const drawTree = (tree: Tree<string>): string => tree.value + draw("\n", tree.forest)
1758
-
1759
- const draw = (indentation: string, forest: Forest<string>): string => {
1760
- let r = ""
1761
- const len = forest.length
1762
- let tree: Tree<string>
1763
- for (let i = 0; i < len; i++) {
1764
- tree = forest[i]
1765
- const isLast = i === len - 1
1766
- r += indentation + (isLast ? "└" : "├") + "─ " + tree.value
1767
- r += draw(indentation + (len > 1 && !isLast ? "│ " : " "), tree.forest)
1768
- }
1769
- return r
1770
- }
1771
-
1772
- const formatTransformationKind = (kind: Transformation["kind"]): string => {
1773
- switch (kind) {
1774
- case "Encoded":
1775
- return "Encoded side transformation failure"
1776
- case "Transformation":
1777
- return "Transformation process failure"
1778
- case "Type":
1779
- return "Type side transformation failure"
1780
- }
1781
- }
1782
-
1783
- const formatRefinementKind = (kind: Refinement["kind"]): string => {
1784
- switch (kind) {
1785
- case "From":
1786
- return "From side refinement failure"
1787
- case "Predicate":
1788
- return "Predicate refinement failure"
1789
- }
1790
- }
1791
-
1792
- const getAnnotated = (issue: ParseIssue): Option.Option<AST.Annotated> =>
1793
- "ast" in issue ? Option.some(issue.ast) : Option.none()
1794
-
1795
- interface CurrentMessage {
1796
- readonly message: string
1797
- readonly override: boolean
1798
- }
1799
-
1800
- // TODO: replace with Either.void when 3.13 lands
1801
- const Either_void = Either.right(undefined)
1802
-
1803
- const getCurrentMessage = (issue: ParseIssue): Effect.Effect<CurrentMessage | undefined> =>
1804
- getAnnotated(issue).pipe(
1805
- Option.flatMap(AST.getMessageAnnotation),
1806
- Option.match({
1807
- onNone: () => Either_void,
1808
- onSome: (messageAnnotation) => {
1809
- const union = messageAnnotation(issue)
1810
- if (Predicate.isString(union)) {
1811
- return Either.right({ message: union, override: false })
1812
- }
1813
- if (Effect.isEffect(union)) {
1814
- return Effect.map(union, (message) => ({ message, override: false }))
1815
- }
1816
- if (Predicate.isString(union.message)) {
1817
- return Either.right({ message: union.message, override: union.override })
1818
- }
1819
- return Effect.map(union.message, (message) => ({ message, override: union.override }))
1820
- }
1821
- })
1822
- )
1823
-
1824
- const createParseIssueGuard =
1825
- <T extends ParseIssue["_tag"]>(tag: T) => (issue: ParseIssue): issue is Extract<ParseIssue, { _tag: T }> =>
1826
- issue._tag === tag
1827
-
1828
- /**
1829
- * Returns `true` if the value is a `Composite`.
1830
- *
1831
- * @category guards
1832
- * @since 3.10.0
1833
- */
1834
- export const isComposite = createParseIssueGuard("Composite")
1835
-
1836
- const isRefinement = createParseIssueGuard("Refinement")
1837
- const isTransformation = createParseIssueGuard("Transformation")
1838
-
1839
- const getMessage = (issue: ParseIssue): Effect.Effect<string | undefined> =>
1840
- flatMap(getCurrentMessage(issue), (currentMessage) => {
1841
- if (currentMessage !== undefined) {
1842
- const useInnerMessage = !currentMessage.override && (
1843
- isComposite(issue) ||
1844
- (isRefinement(issue) && issue.kind === "From") ||
1845
- (isTransformation(issue) && issue.kind !== "Transformation")
1846
- )
1847
- return useInnerMessage
1848
- ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Either_void
1849
- : Either.right(currentMessage.message)
1850
- }
1851
- return Either_void
1852
- })
1853
-
1854
- const getParseIssueTitleAnnotation = (issue: ParseIssue): string | undefined =>
1855
- getAnnotated(issue).pipe(
1856
- Option.flatMap(AST.getParseIssueTitleAnnotation),
1857
- Option.flatMapNullable((annotation) => annotation(issue)),
1858
- Option.getOrUndefined
1859
- )
1860
-
1861
- /** @internal */
1862
- export function getRefinementExpected(ast: AST.Refinement): string {
1863
- return AST.getDescriptionAnnotation(ast).pipe(
1864
- Option.orElse(() => AST.getTitleAnnotation(ast)),
1865
- Option.orElse(() => AST.getAutoTitleAnnotation(ast)),
1866
- Option.orElse(() => AST.getIdentifierAnnotation(ast)),
1867
- Option.getOrElse(() => `{ ${ast.from} | filter }`)
1868
- )
1869
- }
1870
-
1871
- function getDefaultTypeMessage(issue: Type): string {
1872
- if (issue.message !== undefined) {
1873
- return issue.message
1874
- }
1875
- const expected = AST.isRefinement(issue.ast) ? getRefinementExpected(issue.ast) : String(issue.ast)
1876
- return `Expected ${expected}, actual ${Inspectable.formatUnknown(issue.actual)}`
1877
- }
1878
-
1879
- const formatTypeMessage = (issue: Type): Effect.Effect<string> =>
1880
- map(
1881
- getMessage(issue),
1882
- (message) => message ?? getParseIssueTitleAnnotation(issue) ?? getDefaultTypeMessage(issue)
1883
- )
1884
-
1885
- const getParseIssueTitle = (
1886
- issue: Forbidden | Transformation | Refinement | Composite
1887
- ): string => getParseIssueTitleAnnotation(issue) ?? String(issue.ast)
1888
-
1889
- const formatForbiddenMessage = (issue: Forbidden): string => issue.message ?? "is forbidden"
1890
-
1891
- const formatUnexpectedMessage = (issue: Unexpected): string => issue.message ?? "is unexpected"
1892
-
1893
- const formatMissingMessage = (issue: Missing): Effect.Effect<string> => {
1894
- const missingMessageAnnotation = AST.getMissingMessageAnnotation(issue.ast)
1895
- if (Option.isSome(missingMessageAnnotation)) {
1896
- const annotation = missingMessageAnnotation.value()
1897
- return Predicate.isString(annotation) ? Either.right(annotation) : annotation
1898
- }
1899
- return Either.right(issue.message ?? "is missing")
1900
- }
1901
-
1902
- const formatTree = (issue: ParseIssue): Effect.Effect<Tree<string>> => {
1903
- switch (issue._tag) {
1904
- case "Type":
1905
- return map(formatTypeMessage(issue), makeTree)
1906
- case "Forbidden":
1907
- return Either.right(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))]))
1908
- case "Unexpected":
1909
- return Either.right(makeTree(formatUnexpectedMessage(issue)))
1910
- case "Missing":
1911
- return map(formatMissingMessage(issue), makeTree)
1912
- case "Transformation":
1913
- return flatMap(getMessage(issue), (message) => {
1914
- if (message !== undefined) {
1915
- return Either.right(makeTree(message))
1916
- }
1917
- return map(
1918
- formatTree(issue.issue),
1919
- (tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatTransformationKind(issue.kind), [tree])])
1920
- )
1921
- })
1922
- case "Refinement":
1923
- return flatMap(getMessage(issue), (message) => {
1924
- if (message !== undefined) {
1925
- return Either.right(makeTree(message))
1926
- }
1927
- return map(
1928
- formatTree(issue.issue),
1929
- (tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatRefinementKind(issue.kind), [tree])])
1930
- )
1931
- })
1932
- case "Pointer":
1933
- return map(formatTree(issue.issue), (tree) => makeTree(util_.formatPath(issue.path), [tree]))
1934
- case "Composite":
1935
- return flatMap(getMessage(issue), (message) => {
1936
- if (message !== undefined) {
1937
- return Either.right(makeTree(message))
1938
- }
1939
- const parseIssueTitle = getParseIssueTitle(issue)
1940
- return util_.isNonEmpty(issue.issues)
1941
- ? map(Effect.forEach(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest))
1942
- : map(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree]))
1943
- })
1944
- }
1945
- }
1946
-
1947
- /**
1948
- * Represents an issue returned by the {@link ArrayFormatter} formatter.
1949
- *
1950
- * @category model
1951
- * @since 3.10.0
1952
- */
1953
- export interface ArrayFormatterIssue {
1954
- /**
1955
- * The tag identifying the type of parse issue.
1956
- */
1957
- readonly _tag: ParseIssue["_tag"]
1958
-
1959
- /**
1960
- * The path to the property where the issue occurred.
1961
- */
1962
- readonly path: ReadonlyArray<PropertyKey>
1963
-
1964
- /**
1965
- * A descriptive message explaining the issue.
1966
- */
1967
- readonly message: string
1968
- }
1969
-
1970
- const makeArrayFormatterIssue = (
1971
- _tag: ArrayFormatterIssue["_tag"],
1972
- path: ArrayFormatterIssue["path"],
1973
- message: ArrayFormatterIssue["message"]
1974
- ): ArrayFormatterIssue => ({ _tag, path, message })
1975
-
1976
- /**
1977
- * @category formatting
1978
- * @since 3.10.0
1979
- */
1980
- export const ArrayFormatter: ParseResultFormatter<Array<ArrayFormatterIssue>> = {
1981
- formatIssue: (issue) => getArrayFormatterIssues(issue, undefined, []),
1982
- formatIssueSync: (issue) => {
1983
- const e = ArrayFormatter.formatIssue(issue)
1984
- return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e)
1985
- },
1986
- formatError: (error) => ArrayFormatter.formatIssue(error.issue),
1987
- formatErrorSync: (error) => ArrayFormatter.formatIssueSync(error.issue)
1988
- }
1989
-
1990
- const getArrayFormatterIssues = (
1991
- issue: ParseIssue,
1992
- parentTag: ArrayFormatterIssue["_tag"] | undefined,
1993
- path: ReadonlyArray<PropertyKey>
1994
- ): Effect.Effect<Array<ArrayFormatterIssue>> => {
1995
- const _tag = issue._tag
1996
- switch (_tag) {
1997
- case "Type":
1998
- return map(formatTypeMessage(issue), (message) => [makeArrayFormatterIssue(parentTag ?? _tag, path, message)])
1999
- case "Forbidden":
2000
- return Either.right([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))])
2001
- case "Unexpected":
2002
- return Either.right([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))])
2003
- case "Missing":
2004
- return map(formatMissingMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)])
2005
- case "Pointer":
2006
- return getArrayFormatterIssues(issue.issue, undefined, path.concat(issue.path))
2007
- case "Composite":
2008
- return flatMap(getMessage(issue), (message) => {
2009
- if (message !== undefined) {
2010
- return Either.right([makeArrayFormatterIssue(_tag, path, message)])
2011
- }
2012
- return util_.isNonEmpty(issue.issues)
2013
- ? map(Effect.forEach(issue.issues, (issue) => getArrayFormatterIssues(issue, undefined, path)), Arr.flatten)
2014
- : getArrayFormatterIssues(issue.issues, undefined, path)
2015
- })
2016
- case "Refinement":
2017
- return flatMap(getMessage(issue), (message) => {
2018
- if (message !== undefined) {
2019
- return Either.right([makeArrayFormatterIssue(_tag, path, message)])
2020
- }
2021
- return getArrayFormatterIssues(issue.issue, issue.kind === "Predicate" ? _tag : undefined, path)
2022
- })
2023
- case "Transformation":
2024
- return flatMap(getMessage(issue), (message) => {
2025
- if (message !== undefined) {
2026
- return Either.right([makeArrayFormatterIssue(_tag, path, message)])
2027
- }
2028
- return getArrayFormatterIssues(issue.issue, issue.kind === "Transformation" ? _tag : undefined, path)
2029
- })
2030
- }
2031
- }