|
1 | 1 | import { arrayIntercalate } from "collection-utils"; |
2 | 2 |
|
| 3 | +import { minMaxItemsForType } from "../../attributes/Constraints.js"; |
3 | 4 | import { ConvenienceRenderer } from "../../ConvenienceRenderer.js"; |
4 | 5 | import { type Name, type Namer, funPrefixNamer } from "../../Naming.js"; |
5 | 6 | import type { RenderContext } from "../../Renderer.js"; |
@@ -117,11 +118,22 @@ export class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer { |
117 | 118 | (_integerType) => "S.Int", |
118 | 119 | (_doubleType) => "S.Number", |
119 | 120 | (_stringType) => "S.String", |
120 | | - (arrayType) => [ |
121 | | - "S.Array(", |
122 | | - this.typeMapTypeFor(arrayType.items, false), |
123 | | - ")", |
124 | | - ], |
| 121 | + (arrayType) => { |
| 122 | + const [minItems, maxItems] = |
| 123 | + minMaxItemsForType(arrayType) ?? []; |
| 124 | + const schema: Sourcelike[] = [ |
| 125 | + "S.Array(", |
| 126 | + this.typeMapTypeFor(arrayType.items, false), |
| 127 | + ")", |
| 128 | + ]; |
| 129 | + if (minItems !== undefined && minItems > 0) { |
| 130 | + schema.push(".pipe(S.minItems(", minItems.toString(), "))"); |
| 131 | + } |
| 132 | + if (maxItems !== undefined) { |
| 133 | + schema.push(".pipe(S.maxItems(", maxItems.toString(), "))"); |
| 134 | + } |
| 135 | + return schema; |
| 136 | + }, |
125 | 137 | (_classType) => panic("Should already be handled."), |
126 | 138 | (_mapType) => [ |
127 | 139 | "S.Record({ key: S.String, value: ", |
|
0 commit comments