(keySchema: Constraint, annotations?: Annotations.Filter)
| 9075 | * @since 4.0.0 |
| 9076 | */ |
| 9077 | export function isPropertyNames(keySchema: Constraint, annotations?: Annotations.Filter) { |
| 9078 | const propertyNames = toEncoded(keySchema) |
| 9079 | const parser = SchemaParser._issue(propertyNames.ast) |
| 9080 | return makeFilter<object>( |
| 9081 | (input, ast, options) => { |
| 9082 | const keys = InternalRecord.ownEnumerableKeys(input) |
| 9083 | const issues: Array<SchemaIssue.Issue> = [] |
| 9084 | for (const key of keys) { |
| 9085 | const issue = parser(key, options) |
| 9086 | if (issue !== undefined) { |
| 9087 | issues.push(new SchemaIssue.Pointer([key], issue)) |
| 9088 | if (options.errors === "first") break |
| 9089 | } |
| 9090 | } |
| 9091 | if (Arr.isArrayNonEmpty(issues)) { |
| 9092 | return new SchemaIssue.Composite(ast, issues, input, options) |
| 9093 | } |
| 9094 | return true |
| 9095 | }, |
| 9096 | { |
| 9097 | expected: "an object with property names matching the schema", |
| 9098 | representation: { |
| 9099 | id: "effect/schema/isPropertyNames", |
| 9100 | payload: null, |
| 9101 | schemas: [propertyNames.ast] |
| 9102 | }, |
| 9103 | toJsonSchema: ({ schemas, type }) => |
| 9104 | type === "object" ? { propertyNames: schemas[0] } : [{ propertyNames: schemas[0] }, true], |
| 9105 | [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true, |
| 9106 | ...annotations |
| 9107 | } |
| 9108 | ) |
| 9109 | } |
| 9110 | /** |
| 9111 | * Validates that all items in an array are unique according to Effect equality. |
| 9112 | * |
nothing calls this directly
no test coverage detected