@clayroach/effect 3.19.14-source-capture.6 → 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
package/src/Arbitrary.ts DELETED
@@ -1,1101 +0,0 @@
1
- /**
2
- * @since 3.10.0
3
- */
4
-
5
- import * as Arr from "./Array.js"
6
- import * as FastCheck from "./FastCheck.js"
7
- import { globalValue } from "./GlobalValue.js"
8
- import * as errors_ from "./internal/schema/errors.js"
9
- import * as schemaId_ from "./internal/schema/schemaId.js"
10
- import * as util_ from "./internal/schema/util.js"
11
- import * as Option from "./Option.js"
12
- import * as Predicate from "./Predicate.js"
13
- import type * as Schema from "./Schema.js"
14
- import * as SchemaAST from "./SchemaAST.js"
15
- import type * as Types from "./Types.js"
16
-
17
- /**
18
- * @category model
19
- * @since 3.10.0
20
- */
21
- export interface LazyArbitrary<A> {
22
- (fc: typeof FastCheck): FastCheck.Arbitrary<A>
23
- }
24
-
25
- /**
26
- * @category annotations
27
- * @since 3.10.0
28
- */
29
- export interface ArbitraryGenerationContext {
30
- readonly maxDepth: number
31
- readonly depthIdentifier?: string
32
- readonly constraints?: StringConstraints | NumberConstraints | BigIntConstraints | DateConstraints | ArrayConstraints
33
- }
34
-
35
- /**
36
- * @category annotations
37
- * @since 3.10.0
38
- */
39
- export type ArbitraryAnnotation<A, TypeParameters extends ReadonlyArray<any> = readonly []> = (
40
- ...arbitraries: [
41
- ...{ readonly [K in keyof TypeParameters]: LazyArbitrary<TypeParameters[K]> },
42
- ctx: ArbitraryGenerationContext
43
- ]
44
- ) => LazyArbitrary<A>
45
-
46
- /**
47
- * Returns a LazyArbitrary for the `A` type of the provided schema.
48
- *
49
- * @category arbitrary
50
- * @since 3.10.0
51
- */
52
- export const makeLazy = <A, I, R>(schema: Schema.Schema<A, I, R>): LazyArbitrary<A> => {
53
- const description = getDescription(schema.ast, [])
54
- return go(description, { maxDepth: 2 })
55
- }
56
-
57
- /**
58
- * Returns a fast-check Arbitrary for the `A` type of the provided schema.
59
- *
60
- * @category arbitrary
61
- * @since 3.10.0
62
- */
63
- export const make = <A, I, R>(schema: Schema.Schema<A, I, R>): FastCheck.Arbitrary<A> => makeLazy(schema)(FastCheck)
64
-
65
- interface StringConstraints {
66
- readonly _tag: "StringConstraints"
67
- readonly constraints: FastCheck.StringSharedConstraints
68
- readonly pattern?: string
69
- }
70
-
71
- /** @internal */
72
- export const makeStringConstraints = (options: {
73
- readonly minLength?: number | undefined
74
- readonly maxLength?: number | undefined
75
- readonly pattern?: string | undefined
76
- }): StringConstraints => {
77
- const out: Types.Mutable<StringConstraints> = {
78
- _tag: "StringConstraints",
79
- constraints: {}
80
- }
81
- if (Predicate.isNumber(options.minLength)) {
82
- out.constraints.minLength = options.minLength
83
- }
84
- if (Predicate.isNumber(options.maxLength)) {
85
- out.constraints.maxLength = options.maxLength
86
- }
87
- if (Predicate.isString(options.pattern)) {
88
- out.pattern = options.pattern
89
- }
90
- return out
91
- }
92
-
93
- interface NumberConstraints {
94
- readonly _tag: "NumberConstraints"
95
- readonly constraints: FastCheck.FloatConstraints
96
- readonly isInteger: boolean
97
- }
98
-
99
- /** @internal */
100
- export const makeNumberConstraints = (options: {
101
- readonly isInteger?: boolean | undefined
102
- readonly min?: unknown
103
- readonly minExcluded?: boolean | undefined
104
- readonly max?: unknown
105
- readonly maxExcluded?: boolean | undefined
106
- readonly noNaN?: boolean | undefined
107
- readonly noDefaultInfinity?: boolean | undefined
108
- }): NumberConstraints => {
109
- const out: Types.Mutable<NumberConstraints> = {
110
- _tag: "NumberConstraints",
111
- constraints: {},
112
- isInteger: options.isInteger ?? false
113
- }
114
- if (Predicate.isNumber(options.min)) {
115
- out.constraints.min = Math.fround(options.min)
116
- }
117
- if (Predicate.isBoolean(options.minExcluded)) {
118
- out.constraints.minExcluded = options.minExcluded
119
- }
120
- if (Predicate.isNumber(options.max)) {
121
- out.constraints.max = Math.fround(options.max)
122
- }
123
- if (Predicate.isBoolean(options.maxExcluded)) {
124
- out.constraints.maxExcluded = options.maxExcluded
125
- }
126
- if (Predicate.isBoolean(options.noNaN)) {
127
- out.constraints.noNaN = options.noNaN
128
- }
129
- if (Predicate.isBoolean(options.noDefaultInfinity)) {
130
- out.constraints.noDefaultInfinity = options.noDefaultInfinity
131
- }
132
- return out
133
- }
134
-
135
- interface BigIntConstraints {
136
- readonly _tag: "BigIntConstraints"
137
- readonly constraints: FastCheck.BigIntConstraints
138
- }
139
-
140
- /** @internal */
141
- export const makeBigIntConstraints = (options: {
142
- readonly min?: bigint | undefined
143
- readonly max?: bigint | undefined
144
- }): BigIntConstraints => {
145
- const out: Types.Mutable<BigIntConstraints> = {
146
- _tag: "BigIntConstraints",
147
- constraints: {}
148
- }
149
- if (Predicate.isBigInt(options.min)) {
150
- out.constraints.min = options.min
151
- }
152
- if (Predicate.isBigInt(options.max)) {
153
- out.constraints.max = options.max
154
- }
155
- return out
156
- }
157
-
158
- interface ArrayConstraints {
159
- readonly _tag: "ArrayConstraints"
160
- readonly constraints: FastCheck.ArrayConstraints
161
- }
162
-
163
- /** @internal */
164
- export const makeArrayConstraints = (options: {
165
- readonly minLength?: unknown
166
- readonly maxLength?: unknown
167
- }): ArrayConstraints => {
168
- const out: Types.Mutable<ArrayConstraints> = {
169
- _tag: "ArrayConstraints",
170
- constraints: {}
171
- }
172
- if (Predicate.isNumber(options.minLength)) {
173
- out.constraints.minLength = options.minLength
174
- }
175
- if (Predicate.isNumber(options.maxLength)) {
176
- out.constraints.maxLength = options.maxLength
177
- }
178
- return out
179
- }
180
-
181
- interface DateConstraints {
182
- readonly _tag: "DateConstraints"
183
- readonly constraints: FastCheck.DateConstraints
184
- }
185
-
186
- /** @internal */
187
- export const makeDateConstraints = (options: {
188
- readonly min?: Date | undefined
189
- readonly max?: Date | undefined
190
- readonly noInvalidDate?: boolean | undefined
191
- }): DateConstraints => {
192
- const out: Types.Mutable<DateConstraints> = {
193
- _tag: "DateConstraints",
194
- constraints: {}
195
- }
196
- if (Predicate.isDate(options.min)) {
197
- out.constraints.min = options.min
198
- }
199
- if (Predicate.isDate(options.max)) {
200
- out.constraints.max = options.max
201
- }
202
- if (Predicate.isBoolean(options.noInvalidDate)) {
203
- out.constraints.noInvalidDate = options.noInvalidDate
204
- }
205
- return out
206
- }
207
-
208
- type Refinements = ReadonlyArray<SchemaAST.Refinement>
209
-
210
- interface Base {
211
- readonly path: ReadonlyArray<PropertyKey>
212
- readonly refinements: Refinements
213
- readonly annotations: ReadonlyArray<ArbitraryAnnotation<any, any>>
214
- }
215
-
216
- interface StringKeyword extends Base {
217
- readonly _tag: "StringKeyword"
218
- readonly constraints: ReadonlyArray<StringConstraints>
219
- }
220
-
221
- interface NumberKeyword extends Base {
222
- readonly _tag: "NumberKeyword"
223
- readonly constraints: ReadonlyArray<NumberConstraints>
224
- }
225
-
226
- interface BigIntKeyword extends Base {
227
- readonly _tag: "BigIntKeyword"
228
- readonly constraints: ReadonlyArray<BigIntConstraints>
229
- }
230
-
231
- interface DateFromSelf extends Base {
232
- readonly _tag: "DateFromSelf"
233
- readonly constraints: ReadonlyArray<DateConstraints>
234
- }
235
-
236
- interface Declaration extends Base {
237
- readonly _tag: "Declaration"
238
- readonly typeParameters: ReadonlyArray<Description>
239
- readonly ast: SchemaAST.AST
240
- }
241
-
242
- interface TupleType extends Base {
243
- readonly _tag: "TupleType"
244
- readonly constraints: ReadonlyArray<ArrayConstraints>
245
- readonly elements: ReadonlyArray<{
246
- readonly isOptional: boolean
247
- readonly description: Description
248
- }>
249
- readonly rest: ReadonlyArray<Description>
250
- }
251
-
252
- interface TypeLiteral extends Base {
253
- readonly _tag: "TypeLiteral"
254
- readonly propertySignatures: ReadonlyArray<{
255
- readonly isOptional: boolean
256
- readonly name: PropertyKey
257
- readonly value: Description
258
- }>
259
- readonly indexSignatures: ReadonlyArray<{
260
- readonly parameter: Description
261
- readonly value: Description
262
- }>
263
- }
264
-
265
- interface Union extends Base {
266
- readonly _tag: "Union"
267
- readonly members: ReadonlyArray<Description>
268
- }
269
-
270
- interface Suspend extends Base {
271
- readonly _tag: "Suspend"
272
- readonly id: string
273
- readonly ast: SchemaAST.AST
274
- readonly description: () => Description
275
- }
276
-
277
- interface Ref extends Base {
278
- readonly _tag: "Ref"
279
- readonly id: string
280
- readonly ast: SchemaAST.AST
281
- }
282
-
283
- interface NeverKeyword extends Base {
284
- readonly _tag: "NeverKeyword"
285
- readonly ast: SchemaAST.AST
286
- }
287
-
288
- interface Keyword extends Base {
289
- readonly _tag: "Keyword"
290
- readonly value:
291
- | "UndefinedKeyword"
292
- | "VoidKeyword"
293
- | "UnknownKeyword"
294
- | "AnyKeyword"
295
- | "BooleanKeyword"
296
- | "SymbolKeyword"
297
- | "ObjectKeyword"
298
- }
299
-
300
- interface Literal extends Base {
301
- readonly _tag: "Literal"
302
- readonly literal: SchemaAST.LiteralValue
303
- }
304
-
305
- interface UniqueSymbol extends Base {
306
- readonly _tag: "UniqueSymbol"
307
- readonly symbol: symbol
308
- }
309
-
310
- interface Enums extends Base {
311
- readonly _tag: "Enums"
312
- readonly enums: ReadonlyArray<readonly [string, string | number]>
313
- readonly ast: SchemaAST.AST
314
- }
315
-
316
- interface TemplateLiteral extends Base {
317
- readonly _tag: "TemplateLiteral"
318
- readonly head: string
319
- readonly spans: ReadonlyArray<{
320
- readonly description: Description
321
- readonly literal: string
322
- }>
323
- }
324
-
325
- type Description =
326
- | Declaration
327
- | NeverKeyword
328
- | Keyword
329
- | Literal
330
- | UniqueSymbol
331
- | Enums
332
- | TemplateLiteral
333
- | StringKeyword
334
- | NumberKeyword
335
- | BigIntKeyword
336
- | DateFromSelf
337
- | TupleType
338
- | TypeLiteral
339
- | Union
340
- | Suspend
341
- | Ref
342
-
343
- const getArbitraryAnnotation = SchemaAST.getAnnotation<ArbitraryAnnotation<any, any>>(SchemaAST.ArbitraryAnnotationId)
344
-
345
- const getASTConstraints = (ast: SchemaAST.AST) => {
346
- const TypeAnnotationId = ast.annotations[SchemaAST.SchemaIdAnnotationId]
347
- if (Predicate.isPropertyKey(TypeAnnotationId)) {
348
- const out = ast.annotations[TypeAnnotationId]
349
- if (Predicate.isReadonlyRecord(out)) {
350
- return out
351
- }
352
- }
353
- }
354
-
355
- const idMemoMap = globalValue(
356
- Symbol.for("effect/Arbitrary/IdMemoMap"),
357
- () => new Map<SchemaAST.AST, string>()
358
- )
359
-
360
- let counter = 0
361
-
362
- function wrapGetDescription(
363
- f: (ast: SchemaAST.AST, description: Description) => Description,
364
- g: (ast: SchemaAST.AST, path: ReadonlyArray<PropertyKey>) => Description
365
- ): (ast: SchemaAST.AST, path: ReadonlyArray<PropertyKey>) => Description {
366
- return (ast, path) => f(ast, g(ast, path))
367
- }
368
-
369
- function parseMeta(ast: SchemaAST.AST): [SchemaAST.SchemaIdAnnotation | undefined, Record<string | symbol, unknown>] {
370
- const jsonSchema = SchemaAST.getJSONSchemaAnnotation(ast).pipe(
371
- Option.filter(Predicate.isReadonlyRecord),
372
- Option.getOrUndefined
373
- )
374
- const schemaId = Option.getOrElse(SchemaAST.getSchemaIdAnnotation(ast), () => undefined)
375
- const schemaParams = Option.fromNullable(schemaId).pipe(
376
- Option.map((id) => ast.annotations[id]),
377
- Option.filter(Predicate.isReadonlyRecord),
378
- Option.getOrUndefined
379
- )
380
- return [schemaId, { ...schemaParams, ...jsonSchema }]
381
- }
382
-
383
- /** @internal */
384
- export const getDescription = wrapGetDescription(
385
- (ast, description) => {
386
- const annotation = getArbitraryAnnotation(ast)
387
- if (Option.isSome(annotation)) {
388
- return {
389
- ...description,
390
- annotations: [...description.annotations, annotation.value]
391
- }
392
- }
393
- return description
394
- },
395
- (ast, path) => {
396
- const [schemaId, meta] = parseMeta(ast)
397
- switch (ast._tag) {
398
- case "Refinement": {
399
- const from = getDescription(ast.from, path)
400
- switch (from._tag) {
401
- case "StringKeyword":
402
- return {
403
- ...from,
404
- constraints: [...from.constraints, makeStringConstraints(meta)],
405
- refinements: [...from.refinements, ast]
406
- }
407
- case "NumberKeyword": {
408
- const c = schemaId === schemaId_.NonNaNSchemaId ?
409
- makeNumberConstraints({ noNaN: true }) :
410
- schemaId === schemaId_.FiniteSchemaId || schemaId === schemaId_.JsonNumberSchemaId ?
411
- makeNumberConstraints({ noDefaultInfinity: true, noNaN: true }) :
412
- makeNumberConstraints({
413
- isInteger: "type" in meta && meta.type === "integer",
414
- noNaN: undefined,
415
- noDefaultInfinity: undefined,
416
- min: meta.exclusiveMinimum ?? meta.minimum,
417
- minExcluded: "exclusiveMinimum" in meta ? true : undefined,
418
- max: meta.exclusiveMaximum ?? meta.maximum,
419
- maxExcluded: "exclusiveMaximum" in meta ? true : undefined
420
- })
421
- return {
422
- ...from,
423
- constraints: [...from.constraints, c],
424
- refinements: [...from.refinements, ast]
425
- }
426
- }
427
- case "BigIntKeyword": {
428
- const c = getASTConstraints(ast)
429
- return {
430
- ...from,
431
- constraints: c !== undefined ? [...from.constraints, makeBigIntConstraints(c)] : from.constraints,
432
- refinements: [...from.refinements, ast]
433
- }
434
- }
435
- case "TupleType":
436
- return {
437
- ...from,
438
- constraints: [
439
- ...from.constraints,
440
- makeArrayConstraints({
441
- minLength: meta.minItems,
442
- maxLength: meta.maxItems
443
- })
444
- ],
445
- refinements: [...from.refinements, ast]
446
- }
447
- case "DateFromSelf":
448
- return {
449
- ...from,
450
- constraints: [...from.constraints, makeDateConstraints(meta)],
451
- refinements: [...from.refinements, ast]
452
- }
453
- default:
454
- return {
455
- ...from,
456
- refinements: [...from.refinements, ast]
457
- }
458
- }
459
- }
460
- case "Declaration": {
461
- if (schemaId === schemaId_.DateFromSelfSchemaId) {
462
- return {
463
- _tag: "DateFromSelf",
464
- constraints: [makeDateConstraints(meta)],
465
- path,
466
- refinements: [],
467
- annotations: []
468
- }
469
- }
470
- return {
471
- _tag: "Declaration",
472
- typeParameters: ast.typeParameters.map((ast) => getDescription(ast, path)),
473
- path,
474
- refinements: [],
475
- annotations: [],
476
- ast
477
- }
478
- }
479
- case "Literal": {
480
- return {
481
- _tag: "Literal",
482
- literal: ast.literal,
483
- path,
484
- refinements: [],
485
- annotations: []
486
- }
487
- }
488
- case "UniqueSymbol": {
489
- return {
490
- _tag: "UniqueSymbol",
491
- symbol: ast.symbol,
492
- path,
493
- refinements: [],
494
- annotations: []
495
- }
496
- }
497
- case "Enums": {
498
- return {
499
- _tag: "Enums",
500
- enums: ast.enums,
501
- path,
502
- refinements: [],
503
- annotations: [],
504
- ast
505
- }
506
- }
507
- case "TemplateLiteral": {
508
- return {
509
- _tag: "TemplateLiteral",
510
- head: ast.head,
511
- spans: ast.spans.map((span) => ({
512
- description: getDescription(span.type, path),
513
- literal: span.literal
514
- })),
515
- path,
516
- refinements: [],
517
- annotations: []
518
- }
519
- }
520
- case "StringKeyword":
521
- return {
522
- _tag: "StringKeyword",
523
- constraints: [],
524
- path,
525
- refinements: [],
526
- annotations: []
527
- }
528
- case "NumberKeyword":
529
- return {
530
- _tag: "NumberKeyword",
531
- constraints: [],
532
- path,
533
- refinements: [],
534
- annotations: []
535
- }
536
- case "BigIntKeyword":
537
- return {
538
- _tag: "BigIntKeyword",
539
- constraints: [],
540
- path,
541
- refinements: [],
542
- annotations: []
543
- }
544
- case "TupleType":
545
- return {
546
- _tag: "TupleType",
547
- constraints: [],
548
- elements: ast.elements.map((element, i) => ({
549
- isOptional: element.isOptional,
550
- description: getDescription(element.type, [...path, i])
551
- })),
552
- rest: ast.rest.map((element, i) => getDescription(element.type, [...path, i])),
553
- path,
554
- refinements: [],
555
- annotations: []
556
- }
557
- case "TypeLiteral":
558
- return {
559
- _tag: "TypeLiteral",
560
- propertySignatures: ast.propertySignatures.map((ps) => ({
561
- isOptional: ps.isOptional,
562
- name: ps.name,
563
- value: getDescription(ps.type, [...path, ps.name])
564
- })),
565
- indexSignatures: ast.indexSignatures.map((is) => ({
566
- parameter: getDescription(is.parameter, path),
567
- value: getDescription(is.type, path)
568
- })),
569
- path,
570
- refinements: [],
571
- annotations: []
572
- }
573
- case "Union":
574
- return {
575
- _tag: "Union",
576
- members: ast.types.map((member, i) => getDescription(member, [...path, i])),
577
- path,
578
- refinements: [],
579
- annotations: []
580
- }
581
- case "Suspend": {
582
- const memoId = idMemoMap.get(ast)
583
- if (memoId !== undefined) {
584
- return {
585
- _tag: "Ref",
586
- id: memoId,
587
- ast,
588
- path,
589
- refinements: [],
590
- annotations: []
591
- }
592
- }
593
- counter++
594
- const id = `__id-${counter}__`
595
- idMemoMap.set(ast, id)
596
- return {
597
- _tag: "Suspend",
598
- id,
599
- ast,
600
- description: () => getDescription(ast.f(), path),
601
- path,
602
- refinements: [],
603
- annotations: []
604
- }
605
- }
606
- case "Transformation":
607
- return getDescription(ast.to, path)
608
- case "NeverKeyword":
609
- return {
610
- _tag: "NeverKeyword",
611
- path,
612
- refinements: [],
613
- annotations: [],
614
- ast
615
- }
616
- default: {
617
- return {
618
- _tag: "Keyword",
619
- value: ast._tag,
620
- path,
621
- refinements: [],
622
- annotations: []
623
- }
624
- }
625
- }
626
- }
627
- )
628
-
629
- function getMax(n1: Date | undefined, n2: Date | undefined): Date | undefined
630
- function getMax(n1: bigint | undefined, n2: bigint | undefined): bigint | undefined
631
- function getMax(n1: number | undefined, n2: number | undefined): number | undefined
632
- function getMax(
633
- n1: bigint | number | Date | undefined,
634
- n2: bigint | number | Date | undefined
635
- ): bigint | number | Date | undefined {
636
- return n1 === undefined ? n2 : n2 === undefined ? n1 : n1 <= n2 ? n2 : n1
637
- }
638
-
639
- function getMin(n1: Date | undefined, n2: Date | undefined): Date | undefined
640
- function getMin(n1: bigint | undefined, n2: bigint | undefined): bigint | undefined
641
- function getMin(n1: number | undefined, n2: number | undefined): number | undefined
642
- function getMin(
643
- n1: bigint | number | Date | undefined,
644
- n2: bigint | number | Date | undefined
645
- ): bigint | number | Date | undefined {
646
- return n1 === undefined ? n2 : n2 === undefined ? n1 : n1 <= n2 ? n1 : n2
647
- }
648
-
649
- const getOr = (a: boolean | undefined, b: boolean | undefined): boolean | undefined => {
650
- return a === undefined ? b : b === undefined ? a : a || b
651
- }
652
-
653
- function mergePattern(pattern1: string | undefined, pattern2: string | undefined): string | undefined {
654
- if (pattern1 === undefined) {
655
- return pattern2
656
- }
657
- if (pattern2 === undefined) {
658
- return pattern1
659
- }
660
- return `(?:${pattern1})|(?:${pattern2})`
661
- }
662
-
663
- function mergeStringConstraints(c1: StringConstraints, c2: StringConstraints): StringConstraints {
664
- return makeStringConstraints({
665
- minLength: getMax(c1.constraints.minLength, c2.constraints.minLength),
666
- maxLength: getMin(c1.constraints.maxLength, c2.constraints.maxLength),
667
- pattern: mergePattern(c1.pattern, c2.pattern)
668
- })
669
- }
670
-
671
- function buildStringConstraints(description: StringKeyword): StringConstraints | undefined {
672
- return description.constraints.length === 0
673
- ? undefined
674
- : description.constraints.reduce(mergeStringConstraints)
675
- }
676
-
677
- function mergeNumberConstraints(c1: NumberConstraints, c2: NumberConstraints): NumberConstraints {
678
- return makeNumberConstraints({
679
- isInteger: c1.isInteger || c2.isInteger,
680
- min: getMax(c1.constraints.min, c2.constraints.min),
681
- minExcluded: getOr(c1.constraints.minExcluded, c2.constraints.minExcluded),
682
- max: getMin(c1.constraints.max, c2.constraints.max),
683
- maxExcluded: getOr(c1.constraints.maxExcluded, c2.constraints.maxExcluded),
684
- noNaN: getOr(c1.constraints.noNaN, c2.constraints.noNaN),
685
- noDefaultInfinity: getOr(c1.constraints.noDefaultInfinity, c2.constraints.noDefaultInfinity)
686
- })
687
- }
688
-
689
- function buildNumberConstraints(description: NumberKeyword): NumberConstraints | undefined {
690
- return description.constraints.length === 0
691
- ? undefined
692
- : description.constraints.reduce(mergeNumberConstraints)
693
- }
694
-
695
- function mergeBigIntConstraints(c1: BigIntConstraints, c2: BigIntConstraints): BigIntConstraints {
696
- return makeBigIntConstraints({
697
- min: getMax(c1.constraints.min, c2.constraints.min),
698
- max: getMin(c1.constraints.max, c2.constraints.max)
699
- })
700
- }
701
-
702
- function buildBigIntConstraints(description: BigIntKeyword): BigIntConstraints | undefined {
703
- return description.constraints.length === 0
704
- ? undefined
705
- : description.constraints.reduce(mergeBigIntConstraints)
706
- }
707
-
708
- function mergeDateConstraints(c1: DateConstraints, c2: DateConstraints): DateConstraints {
709
- return makeDateConstraints({
710
- min: getMax(c1.constraints.min, c2.constraints.min),
711
- max: getMin(c1.constraints.max, c2.constraints.max),
712
- noInvalidDate: getOr(c1.constraints.noInvalidDate, c2.constraints.noInvalidDate)
713
- })
714
- }
715
-
716
- function buildDateConstraints(description: DateFromSelf): DateConstraints | undefined {
717
- return description.constraints.length === 0
718
- ? undefined
719
- : description.constraints.reduce(mergeDateConstraints)
720
- }
721
-
722
- const constArrayConstraints = makeArrayConstraints({})
723
-
724
- function mergeArrayConstraints(c1: ArrayConstraints, c2: ArrayConstraints): ArrayConstraints {
725
- return makeArrayConstraints({
726
- minLength: getMax(c1.constraints.minLength, c2.constraints.minLength),
727
- maxLength: getMin(c1.constraints.maxLength, c2.constraints.maxLength)
728
- })
729
- }
730
-
731
- function buildArrayConstraints(description: TupleType): ArrayConstraints | undefined {
732
- return description.constraints.length === 0
733
- ? undefined
734
- : description.constraints.reduce(mergeArrayConstraints)
735
- }
736
-
737
- const arbitraryMemoMap = globalValue(
738
- Symbol.for("effect/Arbitrary/arbitraryMemoMap"),
739
- () => new WeakMap<SchemaAST.AST, LazyArbitrary<any>>()
740
- )
741
-
742
- function applyFilters(filters: ReadonlyArray<Predicate.Predicate<any>>, arb: LazyArbitrary<any>): LazyArbitrary<any> {
743
- return (fc) => filters.reduce((arb, filter) => arb.filter(filter), arb(fc))
744
- }
745
-
746
- function absurd(message: string): LazyArbitrary<any> {
747
- return () => {
748
- throw new Error(message)
749
- }
750
- }
751
-
752
- function getContextConstraints(description: Description): ArbitraryGenerationContext["constraints"] {
753
- switch (description._tag) {
754
- case "StringKeyword":
755
- return buildStringConstraints(description)
756
- case "NumberKeyword":
757
- return buildNumberConstraints(description)
758
- case "BigIntKeyword":
759
- return buildBigIntConstraints(description)
760
- case "DateFromSelf":
761
- return buildDateConstraints(description)
762
- case "TupleType":
763
- return buildArrayConstraints(description)
764
- }
765
- }
766
-
767
- function wrapGo(
768
- f: (description: Description, ctx: ArbitraryGenerationContext, lazyArb: LazyArbitrary<any>) => LazyArbitrary<any>,
769
- g: (description: Description, ctx: ArbitraryGenerationContext) => LazyArbitrary<any>
770
- ): (description: Description, ctx: ArbitraryGenerationContext) => LazyArbitrary<any> {
771
- return (description, ctx) => f(description, ctx, g(description, ctx))
772
- }
773
-
774
- const go = wrapGo(
775
- (description, ctx, lazyArb) => {
776
- const annotation: ArbitraryAnnotation<any, any> | undefined =
777
- description.annotations[description.annotations.length - 1]
778
-
779
- // error handling
780
- if (annotation === undefined) {
781
- switch (description._tag) {
782
- case "Declaration":
783
- case "NeverKeyword":
784
- throw new Error(errors_.getArbitraryMissingAnnotationErrorMessage(description.path, description.ast))
785
- case "Enums":
786
- if (description.enums.length === 0) {
787
- throw new Error(errors_.getArbitraryEmptyEnumErrorMessage(description.path))
788
- }
789
- }
790
- }
791
-
792
- const filters = description.refinements.map((ast) => (a: any) =>
793
- Option.isNone(ast.filter(a, SchemaAST.defaultParseOption, ast))
794
- )
795
- if (annotation === undefined) {
796
- return applyFilters(filters, lazyArb)
797
- }
798
-
799
- const constraints = getContextConstraints(description)
800
- if (constraints !== undefined) {
801
- ctx = { ...ctx, constraints }
802
- }
803
-
804
- if (description._tag === "Declaration") {
805
- return applyFilters(filters, annotation(...description.typeParameters.map((p) => go(p, ctx)), ctx))
806
- }
807
- if (description.refinements.length > 0) {
808
- // TODO(4.0): remove the `lazyArb` parameter
809
- return applyFilters(filters, annotation(lazyArb, ctx))
810
- }
811
- return annotation(ctx)
812
- },
813
- (description, ctx) => {
814
- switch (description._tag) {
815
- case "DateFromSelf": {
816
- const constraints = buildDateConstraints(description)
817
- return (fc) => fc.date(constraints?.constraints)
818
- }
819
- case "Declaration":
820
- case "NeverKeyword":
821
- return absurd(`BUG: cannot generate an arbitrary for ${description._tag}`)
822
- case "Literal":
823
- return (fc) => fc.constant(description.literal)
824
- case "UniqueSymbol":
825
- return (fc) => fc.constant(description.symbol)
826
- case "Keyword": {
827
- switch (description.value) {
828
- case "UndefinedKeyword":
829
- return (fc) => fc.constant(undefined)
830
- case "VoidKeyword":
831
- case "UnknownKeyword":
832
- case "AnyKeyword":
833
- return (fc) => fc.anything()
834
- case "BooleanKeyword":
835
- return (fc) => fc.boolean()
836
- case "SymbolKeyword":
837
- return (fc) => fc.string().map((s) => Symbol.for(s))
838
- case "ObjectKeyword":
839
- return (fc) => fc.oneof(fc.object(), fc.array(fc.anything()))
840
- }
841
- }
842
- case "Enums":
843
- return (fc) => fc.oneof(...description.enums.map(([_, value]) => fc.constant(value)))
844
- case "TemplateLiteral": {
845
- return (fc) => {
846
- const string = fc.string({ maxLength: 5 })
847
- const number = fc.float({ noDefaultInfinity: true, noNaN: true })
848
-
849
- const getTemplateLiteralArb = (description: TemplateLiteral) => {
850
- const components: Array<FastCheck.Arbitrary<string | number>> = description.head !== ""
851
- ? [fc.constant(description.head)]
852
- : []
853
-
854
- const getTemplateLiteralSpanTypeArb = (
855
- description: Description
856
- ): FastCheck.Arbitrary<string | number> => {
857
- switch (description._tag) {
858
- case "StringKeyword":
859
- return string
860
- case "NumberKeyword":
861
- return number
862
- case "Literal":
863
- return fc.constant(String(description.literal))
864
- case "Union":
865
- return fc.oneof(...description.members.map(getTemplateLiteralSpanTypeArb))
866
- case "TemplateLiteral":
867
- return getTemplateLiteralArb(description)
868
- default:
869
- return fc.constant("")
870
- }
871
- }
872
-
873
- description.spans.forEach((span) => {
874
- components.push(getTemplateLiteralSpanTypeArb(span.description))
875
- if (span.literal !== "") {
876
- components.push(fc.constant(span.literal))
877
- }
878
- })
879
-
880
- return fc.tuple(...components).map((spans) => spans.join(""))
881
- }
882
-
883
- return getTemplateLiteralArb(description)
884
- }
885
- }
886
- case "StringKeyword": {
887
- const constraints = buildStringConstraints(description)
888
- const pattern = constraints?.pattern
889
- return pattern !== undefined ?
890
- (fc) => fc.stringMatching(new RegExp(pattern)) :
891
- (fc) => fc.string(constraints?.constraints)
892
- }
893
- case "NumberKeyword": {
894
- const constraints = buildNumberConstraints(description)
895
- return constraints?.isInteger ?
896
- (fc) => fc.integer(constraints.constraints) :
897
- (fc) => fc.float(constraints?.constraints)
898
- }
899
- case "BigIntKeyword": {
900
- const constraints = buildBigIntConstraints(description)
901
- return (fc) => fc.bigInt(constraints?.constraints ?? {})
902
- }
903
- case "TupleType": {
904
- const elements: Array<LazyArbitrary<any>> = []
905
- let hasOptionals = false
906
- for (const element of description.elements) {
907
- elements.push(go(element.description, ctx))
908
- if (element.isOptional) {
909
- hasOptionals = true
910
- }
911
- }
912
- const rest = description.rest.map((d) => go(d, ctx))
913
- return (fc) => {
914
- // ---------------------------------------------
915
- // handle elements
916
- // ---------------------------------------------
917
- let output = fc.tuple(...elements.map((arb) => arb(fc)))
918
- if (hasOptionals) {
919
- const indexes = fc.tuple(
920
- ...description.elements.map((element) => element.isOptional ? fc.boolean() : fc.constant(true))
921
- )
922
- output = output.chain((tuple) =>
923
- indexes.map((booleans) => {
924
- for (const [i, b] of booleans.reverse().entries()) {
925
- if (!b) {
926
- tuple.splice(booleans.length - i, 1)
927
- }
928
- }
929
- return tuple
930
- })
931
- )
932
- }
933
-
934
- // ---------------------------------------------
935
- // handle rest element
936
- // ---------------------------------------------
937
- if (Arr.isNonEmptyReadonlyArray(rest)) {
938
- const constraints = buildArrayConstraints(description) ?? constArrayConstraints
939
- const [head, ...tail] = rest
940
- const item = head(fc)
941
- output = output.chain((as) => {
942
- const len = as.length
943
- // We must adjust the constraints for the rest element
944
- // because the elements might have generated some values
945
- const restArrayConstraints = subtractElementsLength(constraints.constraints, len)
946
- if (restArrayConstraints.maxLength === 0) {
947
- return fc.constant(as)
948
- }
949
- /*
950
-
951
- `getSuspendedArray` is used to generate less values in
952
- the context of a recursive schema. Without it, the following schema
953
- would generate an big amount of values possibly leading to a stack
954
- overflow:
955
-
956
- ```ts
957
- type A = ReadonlyArray<A | null>
958
-
959
- const schema = S.Array(
960
- S.NullOr(S.suspend((): S.Schema<A> => schema))
961
- )
962
- ```
963
-
964
- */
965
- const arr = ctx.depthIdentifier !== undefined
966
- ? getSuspendedArray(fc, ctx.depthIdentifier, ctx.maxDepth, item, restArrayConstraints)
967
- : fc.array(item, restArrayConstraints)
968
- if (len === 0) {
969
- return arr
970
- }
971
- return arr.map((rest) => [...as, ...rest])
972
- })
973
- // ---------------------------------------------
974
- // handle post rest elements
975
- // ---------------------------------------------
976
- for (let j = 0; j < tail.length; j++) {
977
- output = output.chain((as) => tail[j](fc).map((a) => [...as, a]))
978
- }
979
- }
980
-
981
- return output
982
- }
983
- }
984
- case "TypeLiteral": {
985
- const propertySignatures: Array<LazyArbitrary<any>> = []
986
- const requiredKeys: Array<PropertyKey> = []
987
- for (const ps of description.propertySignatures) {
988
- if (!ps.isOptional) {
989
- requiredKeys.push(ps.name)
990
- }
991
- propertySignatures.push(go(ps.value, ctx))
992
- }
993
- const indexSignatures = description.indexSignatures.map((is) =>
994
- [go(is.parameter, ctx), go(is.value, ctx)] as const
995
- )
996
- return (fc) => {
997
- const pps: any = {}
998
- for (let i = 0; i < propertySignatures.length; i++) {
999
- const ps = description.propertySignatures[i]
1000
- pps[ps.name] = propertySignatures[i](fc)
1001
- }
1002
- let output = fc.record<any, any>(pps, { requiredKeys })
1003
- // ---------------------------------------------
1004
- // handle index signatures
1005
- // ---------------------------------------------
1006
- for (let i = 0; i < indexSignatures.length; i++) {
1007
- const key = indexSignatures[i][0](fc)
1008
- const value = indexSignatures[i][1](fc)
1009
- output = output.chain((o) => {
1010
- const item = fc.tuple(key, value)
1011
- /*
1012
-
1013
- `getSuspendedArray` is used to generate less key/value pairs in
1014
- the context of a recursive schema. Without it, the following schema
1015
- would generate an big amount of values possibly leading to a stack
1016
- overflow:
1017
-
1018
- ```ts
1019
- type A = { [_: string]: A }
1020
-
1021
- const schema = S.Record({ key: S.String, value: S.suspend((): S.Schema<A> => schema) })
1022
- ```
1023
-
1024
- */
1025
- const arr = ctx.depthIdentifier !== undefined ?
1026
- getSuspendedArray(fc, ctx.depthIdentifier, ctx.maxDepth, item, { maxLength: 2 }) :
1027
- fc.array(item)
1028
- return arr.map((tuples) => ({ ...Object.fromEntries(tuples), ...o }))
1029
- })
1030
- }
1031
-
1032
- return output
1033
- }
1034
- }
1035
- case "Union": {
1036
- const members = description.members.map((member) => go(member, ctx))
1037
- return (fc) => fc.oneof(...members.map((arb) => arb(fc)))
1038
- }
1039
- case "Suspend": {
1040
- const memo = arbitraryMemoMap.get(description.ast)
1041
- if (memo) {
1042
- return memo
1043
- }
1044
- if (ctx.depthIdentifier === undefined) {
1045
- ctx = { ...ctx, depthIdentifier: description.id }
1046
- }
1047
- const get = util_.memoizeThunk(() => {
1048
- return go(description.description(), ctx)
1049
- })
1050
- const out: LazyArbitrary<any> = (fc) => fc.constant(null).chain(() => get()(fc))
1051
- arbitraryMemoMap.set(description.ast, out)
1052
- return out
1053
- }
1054
- case "Ref": {
1055
- const memo = arbitraryMemoMap.get(description.ast)
1056
- if (memo) {
1057
- return memo
1058
- }
1059
- throw new Error(`BUG: Ref ${JSON.stringify(description.id)} not found`)
1060
- }
1061
- }
1062
- }
1063
- )
1064
-
1065
- function subtractElementsLength(
1066
- constraints: FastCheck.ArrayConstraints,
1067
- len: number
1068
- ): FastCheck.ArrayConstraints {
1069
- if (len === 0 || (constraints.minLength === undefined && constraints.maxLength === undefined)) {
1070
- return constraints
1071
- }
1072
- const out = { ...constraints }
1073
- if (out.minLength !== undefined) {
1074
- out.minLength = Math.max(out.minLength - len, 0)
1075
- }
1076
- if (out.maxLength !== undefined) {
1077
- out.maxLength = Math.max(out.maxLength - len, 0)
1078
- }
1079
- return out
1080
- }
1081
-
1082
- const getSuspendedArray = (
1083
- fc: typeof FastCheck,
1084
- depthIdentifier: string,
1085
- maxDepth: number,
1086
- item: FastCheck.Arbitrary<any>,
1087
- constraints: FastCheck.ArrayConstraints
1088
- ) => {
1089
- // In the context of a recursive schema, we don't want a `maxLength` greater than 2.
1090
- // The only exception is when `minLength` is also set, in which case we set
1091
- // `maxLength` to the minimum value, which is `minLength`.
1092
- const maxLengthLimit = Math.max(2, constraints.minLength ?? 0)
1093
- if (constraints.maxLength !== undefined && constraints.maxLength > maxLengthLimit) {
1094
- constraints = { ...constraints, maxLength: maxLengthLimit }
1095
- }
1096
- return fc.oneof(
1097
- { maxDepth, depthIdentifier },
1098
- fc.constant([]),
1099
- fc.array(item, constraints)
1100
- )
1101
- }