Function: validateLixSchema()

validateLixSchema(schema: unknown, data: unknown): boolean

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

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);
}

Parameters

ParameterTypeDescription
schemaunknownThe Lix schema definition to validate against
dataunknownThe data to validate

Returns

boolean

true if both the schema and data are valid

Throws

Error with validation details if either validation fails