Hyperlinkv0.8.0-beta.28

Schema

Schema.isPropertyNamesfunctioneffect/Schema.ts:8388
(
  keySchema: Constraint,
  annotations?: Annotations.Filter
): SchemaAST.Filter<object>

Validates that every own property key of an object satisfies the encoded side of the provided key schema.

Details

This check uses Reflect.ownKeys, so symbol keys are validated in addition to string property names.

JSON Schema: For string property names, this corresponds to the propertyNames constraint in JSON Schema.

Object checks
Source effect/Schema.ts:838830 lines
export function isPropertyNames(keySchema: Constraint, annotations?: Annotations.Filter) {
  const propertyNames = toEncoded(keySchema)
  const parser = SchemaParser._issue(propertyNames.ast)
  return makeFilter<object>(
    (input, ast, options) => {
      const keys = Reflect.ownKeys(input)
      const issues: Array<SchemaIssue.Issue> = []
      for (const key of keys) {
        const issue = parser(key, options)
        if (issue !== undefined) {
          issues.push(new SchemaIssue.Pointer([key], issue))
          if (options.errors === "first") break
        }
      }
      if (Arr.isArrayNonEmpty(issues)) {
        return new SchemaIssue.Composite(ast, Option_.some(input), issues)
      }
      return true
    },
    {
      expected: "an object with property names matching the schema",
      meta: {
        _tag: "isPropertyNames",
        propertyNames: propertyNames.ast
      },
      [SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
      ...annotations
    }
  )
}
Referenced by 1 symbols