UNPKG

@csvw-rdf-convertor/core

Version:

This library was generated with [Nx](https://nx.dev).

51 lines (50 loc) 2.1 kB
import { validateDialect } from './dialect.js'; import { validateAllowedKeys, validateArray, validateChild, validateType, validateObject } from './generic.js'; import { inhPropKeys, validateInheritedProperties } from './inherited-properties.js'; import { validateTable } from './table.js'; import { validateTemplate } from './template.js'; const tgSchema = { tableDirection: { type: 'string', validate: (v)=>v === 'ltr' || v === 'rtl' || v === 'auto' } }; const tgKeys = [ ...inhPropKeys, 'tables', 'dialect', 'notes', 'tableDirection', 'tableSchema', 'transformations', '@id', '@type', '@context' ]; /** * Validates a `CsvwTableGroupDescription` object against the defined schema and rules. * * This function performs a series of checks to ensure that the provided table group * adheres to the CSVW (CSV on the Web) specifications. It validates the allowed keys, * object structure, inherited properties, and child elements such as `dialect`, `tables`, * and `transformations`. Additionally, it ensures that the table group contains at least * one table and has the correct type. * * @param {CsvwTableGroupDescription} tg - The table group description object to validate. * @param {ValidationContext} ctx - The context object containing validation utilities and an issue tracker. * * @throws Will add errors to the issue tracker in the context if validation fails. */ export function validateTableGroup(tg, ctx) { var _tg_tables; validateAllowedKeys(tg, tgKeys, 'Table group', ctx); validateObject(tg, tgSchema, 'Table group', ctx); validateInheritedProperties(tg, 'Table group', ctx); validateChild(tg, 'dialect', validateDialect, ctx); if (!((_tg_tables = tg.tables) == null ? void 0 : _tg_tables.length)) { ctx.issueTracker.addError('Table group must contain at least one table'); } validateType(tg, 'TableGroup', ctx); validateArray(tg, 'transformations', validateTemplate, ctx); validateArray(tg, 'tables', validateTable, ctx); } //# sourceMappingURL=table-group.js.map