Skip to content

verifySchemaStructure

verifySchemaStructure(input): void

(Internal Function) - Validates the structure and identifier of a schema to ensure consistency and correctness within the Cord network.

Functionality:

  1. Schema Structure Validation: The function checks that the provided schema conforms to the expected format as defined by SchemaModel. This ensures the schema’s structure adheres to required standards.
  2. Identifier Validation: The schema’s $id (identifier) is verified against a URI generated using the schema’s content, the creator’s DID, and the space identifier. This ensures the uniqueness and correctness of the schema’s identifier within the network.

Parameters:

Parameters

input: ISchema

The schema object to validate. It must comply with the ISchema interface structure, including a valid $id property.

Returns

void

Throws

  • If the actual $id of the schema does not match the expected URI generated using the schema’s content, creator’s DID, and space identifier. This error ensures the schema’s identifier is accurate and prevents conflicts in schema identification.

Example Usage:

try {
verifySchemaStructure(schemaObject);
console.log('Schema is valid and consistent.');
} catch (error) {
console.error('Schema validation failed:', error);
}

Internal Usage:

This function plays a critical role in maintaining data integrity and preventing inconsistencies in schema management by ensuring that every schema’s identifier is correctly derived from its content and metadata.

Source

schema/src/Schema.ts:260