MCPcopy Create free account
hub / github.com/Effect-TS/effect / isPropertyNames

Function isPropertyNames

packages/effect/src/Schema.ts:9077–9109  ·  view source on GitHub ↗
(keySchema: Constraint, annotations?: Annotations.Filter)

Source from the content-addressed store, hash-verified

9075 * @since 4.0.0
9076 */
9077export 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 *

Callers

nothing calls this directly

Calls 4

toEncodedInterface · 0.70
makeFilterFunction · 0.70
parserFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected