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/dist/cjs/Arbitrary.js +38 -23
- package/dist/cjs/Arbitrary.js.map +1 -1
- package/dist/cjs/SchemaAST.js +1 -1
- package/dist/cjs/SchemaAST.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/esm/Arbitrary.js +38 -23
- package/dist/esm/Arbitrary.js.map +1 -1
- package/dist/esm/SchemaAST.js +1 -1
- package/dist/esm/SchemaAST.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Arbitrary.ts +42 -24
- package/src/SchemaAST.ts +1 -1
- package/src/internal/version.ts +1 -1
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
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 => {
|
package/src/internal/version.ts
CHANGED