• Prepare a JSON Schema for graph traversal / SPARQL CONSTRUCT generation.

    Two phases (intentionally separate concerns):

    1. Dereference — inline all $ref targets (dereferenceSchema). This is denormalization in the database sense: factored definitions are duplicated at each use site so downstream code can walk .properties without resolution.
    2. Project — prune by the selection set (projectSchema: select / include / omit / where).

    Prefer calling the phases separately when you need only one of them. Reserve "normalize" / "canonicalize" for true normal-form transforms such as canonicalizeSchemaForFingerprint in @graviola/json-schema-utils.

    Type Parameters

    • T = any

      Type to derive filter patterns from (typically z.infer<typeof zodSchema>)

    Parameters

    Returns TraversalSchema

    A TraversalSchema (dereferenced then projected)

    const traversal = buildTraversalSchema(schema, {
    include: { tags: { take: 10 } },
    includeRelationsByDefault: false
    });

    // With Zod type inference for type safety
    import { z } from 'zod';
    const zodSchema = z.object({
    name: z.string(),
    tags: z.array(z.object({ label: z.string() }))
    });
    type MyType = z.infer<typeof zodSchema>;

    const traversal2 = buildTraversalSchema<MyType>(schema, {
    include: { tags: { take: 10 } } // Type-safe: only valid keys allowed
    });