(keySchema: Constraint, annotations?: Annotations.Filter)
| 9409 | * @since 4.0.0 |
| 9410 | */ |
| 9411 | export function isPropertyNames(keySchema: Constraint, annotations?: Annotations.Filter) { |
| 9412 | const propertyNames = toEncoded(keySchema) |
| 9413 | const parser = SchemaParser._issue(propertyNames.ast) |
| 9414 | return makeFilter<object>( |
| 9415 | (input, ast, options) => { |
| 9416 | const keys = Reflect.ownKeys(input) |
| 9417 | const issues: Array<SchemaIssue.Issue> = [] |
| 9418 | for (const key of keys) { |
| 9419 | const issue = parser(key, options) |
| 9420 | if (issue !== undefined) { |
| 9421 | issues.push(new SchemaIssue.Pointer([key], issue)) |
| 9422 | if (options.errors === "first") break |
| 9423 | } |
| 9424 | } |
| 9425 | if (Arr.isArrayNonEmpty(issues)) { |
| 9426 | return new SchemaIssue.Composite(ast, issues, input, options) |
| 9427 | } |
| 9428 | return true |
| 9429 | }, |
| 9430 | { |
| 9431 | expected: "an object with property names matching the schema", |
| 9432 | representation: { |
| 9433 | id: "effect/schema/isPropertyNames", |
| 9434 | payload: null, |
| 9435 | schemas: [propertyNames.ast] |
| 9436 | }, |
| 9437 | toJsonSchema: ({ schemas }) => ({ propertyNames: schemas[0] }), |
| 9438 | toCode: ({ schemas }) => ({ runtime: `Schema.isPropertyNames(${schemas[0].runtime})` }), |
| 9439 | [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true, |
| 9440 | ...annotations |
| 9441 | } |
| 9442 | ) |
| 9443 | } |
| 9444 | |
| 9445 | /** |
| 9446 | * Reviver for persisted `isPropertyNames` checks. |
no test coverage detected