Function: validateLixSchema()

validateLixSchema(schema, data): boolean

Validates that a schema conforms to the LixSchemaDefinition format and then validates data against that schema.

Parameters

schema

unknown

The Lix schema definition to validate against

data

unknown

The data to validate

Returns

boolean

true if both the schema and data are valid

Throws

Error with validation details if either validation fails

Example

const userSchema = {
  "x-lix-key": "user",
  "x-lix-version": "1.0",
  type: "object",
  properties: {
    id: { type: "string" },
    name: { type: "string" },
    age: { type: "number" }
  },
  required: ["id", "name"]
} as const satisfies LixSchemaDefinition;

const userData = {
  id: "123",
  name: "John Doe",
  age: 30
};

try {
  validateLixSchema(userSchema, userData); // returns true
} catch (error) {
  console.error("Validation failed:", error);
}