basant307/AI_Governance_Project
048
1/**2 * @import {Info, Space} from 'property-information'3 */4 5/**6 * @typedef Definition7 * Definition of a schema.8 * @property {Record<string, string> | undefined} [attributes]9 * Normalzed names to special attribute case.10 * @property {ReadonlyArray<string> | undefined} [mustUseProperty]11 * Normalized names that must be set as properties.12 * @property {Record<string, number | null>} properties13 * Property names to their types.14 * @property {Space | undefined} [space]15 * Space.16 * @property {Transform} transform17 * Transform a property name.18 */19 20/**21 * @callback Transform22 * Transform.23 * @param {Record<string, string>} attributes24 * Attributes.25 * @param {string} property26 * Property.27 * @returns {string}28 * Attribute.29 */30 31import {normalize} from '../normalize.js'32import {DefinedInfo} from './defined-info.js'33import {Schema} from './schema.js'34 35/**36 * @param {Definition} definition37 * Definition.38 * @returns {Schema}39 * Schema.40 */41export function create(definition) {42 /** @type {Record<string, Info>} */43 const properties = {}44 /** @type {Record<string, string>} */45 const normals = {}46 47 for (const [property, value] of Object.entries(definition.properties)) {48 const info = new DefinedInfo(49 property,50 definition.transform(definition.attributes || {}, property),51 value,52 definition.space53 )54 55 if (56 definition.mustUseProperty &&57 definition.mustUseProperty.includes(property)58 ) {59 info.mustUseProperty = true60 }61 62 properties[property] = info63 64 normals[normalize(property)] = property65 normals[normalize(info.attribute)] = property66 }67 68 return new Schema(properties, normals, definition.space)69}70 