buildFromProperties
buildFromProperties(
schema
,spaceUri
,creatorUri
):ISchemaDetails
Constructs a schema object from specified properties, required fields, and other schema attributes. This function is pivotal in dynamically generating schemas based on specific requirements and attributes, facilitating the creation of structured and standardized schema objects.
Parameters
• schema: ISchema
An object defining the properties, required fields, and other attributes of the schema. This includes the structure and data types for each field within the schema, providing the blueprint for the schema’s format and content.
• spaceUri: space:cord:${string}
• creatorUri: did:cord:3${string}
Returns
- A fully constructed schema object including the schema itself, its cryptographic digest, the space identifier, and the creator’s DID. This object can be utilized for data validation and various other purposes, serving as a cornerstone in data structuring and management.
Throws
- If the constructed schema fails to conform to the expected structure or standards. This error ensures the integrity and compliance of the schema with predefined models.
Example
const properties = { title: 'Person', type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer' }, }, required: ['name']};const creatorDid = 'did:example:creator';const spaceId = 'exampleSpaceId';
try { const { schema, digest, space, creator } = buildFromProperties(properties, creatorDid, spaceId); console.log('Constructed Schema:', schema); console.log('Schema Digest:', digest); console.log('Space ID:', space); console.log('Creator DID:', creator);} catch (error) { console.error('Error constructing schema:', error);}