effect 3.12.2 → 3.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Arbitrary.ts CHANGED
@@ -360,31 +360,39 @@ export const toOp = (
360
360
  case "TemplateLiteral":
361
361
  return new Succeed((fc) => {
362
362
  const string = fc.string({ maxLength: 5 })
363
- const number = fc.float({ noDefaultInfinity: true }).filter((n) => !Number.isNaN(n))
364
-
365
- const components: Array<FastCheck.Arbitrary<string | number>> = ast.head !== "" ? [fc.constant(ast.head)] : []
366
-
367
- const addArb = (ast: AST.TemplateLiteralSpan["type"]) => {
368
- switch (ast._tag) {
369
- case "StringKeyword":
370
- return components.push(string)
371
- case "NumberKeyword":
372
- return components.push(number)
373
- case "Literal":
374
- return components.push(fc.constant(String(ast.literal)))
375
- case "Union":
376
- return ast.types.forEach(addArb)
363
+ const number = fc.float({ noDefaultInfinity: true, noNaN: true })
364
+
365
+ const getTemplateLiteralArb = (ast: AST.TemplateLiteral) => {
366
+ const components: Array<FastCheck.Arbitrary<string | number>> = ast.head !== "" ? [fc.constant(ast.head)] : []
367
+
368
+ const getTemplateLiteralSpanTypeArb = (
369
+ ast: AST.TemplateLiteralSpan["type"]
370
+ ): FastCheck.Arbitrary<string | number> => {
371
+ switch (ast._tag) {
372
+ case "StringKeyword":
373
+ return string
374
+ case "NumberKeyword":
375
+ return number
376
+ case "Literal":
377
+ return fc.constant(String(ast.literal))
378
+ case "Union":
379
+ return fc.oneof(...ast.types.map(getTemplateLiteralSpanTypeArb))
380
+ case "TemplateLiteral":
381
+ return getTemplateLiteralArb(ast)
382
+ }
377
383
  }
378
- }
379
384
 
380
- ast.spans.forEach((span) => {
381
- addArb(span.type)
382
- if (span.literal !== "") {
383
- components.push(fc.constant(span.literal))
384
- }
385
- })
385
+ ast.spans.forEach((span) => {
386
+ components.push(getTemplateLiteralSpanTypeArb(span.type))
387
+ if (span.literal !== "") {
388
+ components.push(fc.constant(span.literal))
389
+ }
390
+ })
386
391
 
387
- return fc.tuple(...components).map((spans) => spans.join(""))
392
+ return fc.tuple(...components).map((spans) => spans.join(""))
393
+ }
394
+
395
+ return getTemplateLiteralArb(ast)
388
396
  })
389
397
  case "Refinement": {
390
398
  const from = toOp(ast.from, ctx, path)
@@ -452,7 +460,7 @@ export const toOp = (
452
460
  return new Succeed((fc) => fc.constant(null).chain(() => get()(fc)))
453
461
  }
454
462
  case "Transformation":
455
- return new Succeed(go(ast.to, ctx, path))
463
+ return toOp(ast.to, ctx, path)
456
464
  }
457
465
  }
458
466
 
@@ -577,6 +585,16 @@ const getOr = (a: boolean | undefined, b: boolean | undefined): boolean | undefi
577
585
  return a === undefined ? b : b === undefined ? a : a || b
578
586
  }
579
587
 
588
+ function mergePattern(pattern1: string | undefined, pattern2: string | undefined): string | undefined {
589
+ if (pattern1 === undefined) {
590
+ return pattern2
591
+ }
592
+ if (pattern2 === undefined) {
593
+ return pattern1
594
+ }
595
+ return `(?:${pattern1})|(?:${pattern2})`
596
+ }
597
+
580
598
  const merge = (c1: Config, c2: Constraints | undefined): Config => {
581
599
  if (c2) {
582
600
  switch (c1._tag) {
@@ -585,7 +603,7 @@ const merge = (c1: Config, c2: Constraints | undefined): Config => {
585
603
  return makeStringConstraints({
586
604
  minLength: getMax(c1.constraints.minLength, c2.constraints.minLength),
587
605
  maxLength: getMin(c1.constraints.maxLength, c2.constraints.maxLength),
588
- pattern: c1.pattern ?? c2.pattern
606
+ pattern: mergePattern(c1.pattern, c2.pattern)
589
607
  })
590
608
  }
591
609
  break
package/src/SchemaAST.ts CHANGED
@@ -2100,7 +2100,7 @@ export const annotations = (ast: AST, a: Annotations): AST => {
2100
2100
  */
2101
2101
  export const keyof = (ast: AST): AST => Union.unify(_keyof(ast))
2102
2102
 
2103
- const STRING_KEYWORD_PATTERN = ".*"
2103
+ const STRING_KEYWORD_PATTERN = "[\\s\\S]*" // any string, including newlines
2104
2104
  const NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"
2105
2105
 
2106
2106
  const getTemplateLiteralSpanTypePattern = (type: TemplateLiteralSpanType, capture: boolean): string => {
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.12.2"
1
+ let moduleVersion = "3.12.3"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4