| 1188 | options?: ArrayOptions |
| 1189 | ): Config<ReadonlyArray<V["Type"]>> |
| 1190 | export function Array<V extends Schema.ConstraintCodec<unknown, unknown>>( |
| 1191 | value: V, |
| 1192 | pathOrOptions?: string | Path | ArrayOptions, |
| 1193 | options?: ArrayOptions |
| 1194 | ) { |
| 1195 | const hasPath = isPath(pathOrOptions) |
| 1196 | const resolvedOptions = hasPath ? options : pathOrOptions |
| 1197 | const array = Schema.Array(value) |
| 1198 | const separator = resolvedOptions?.separator ?? "," |
| 1199 | const arrayString = Schema.String.pipe( |
| 1200 | Schema.decodeTo(Schema.toCodecStringTree(array), { |
| 1201 | decode: SchemaGetter.split(resolvedOptions), |
| 1202 | encode: SchemaGetter.compose( |
| 1203 | SchemaGetter.passthrough<ReadonlyArray<string>, Schema.StringTree>({ strict: false }), |
| 1204 | SchemaGetter.transform((input) => input.join(separator)) |
| 1205 | ) |
| 1206 | }) |
| 1207 | ) |
| 1208 | return schema(Schema.Union([arrayString, array]), hasPath ? pathOrOptions : undefined) |
| 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * Creates a config for record values that may also be read from a separated key-value string. |