Skip to content

Port TypeScript reimplementation of schema parsing to JavaScript#766

Open
happy5214 wants to merge 3 commits into
mainfrom
port-schema-loading-from-typescript
Open

Port TypeScript reimplementation of schema parsing to JavaScript#766
happy5214 wants to merge 3 commits into
mainfrom
port-schema-loading-from-typescript

Conversation

@happy5214

Copy link
Copy Markdown
Member

I simply decided to copy over the tsc compilation of the TypeScript code rather than do anything manual. I had to make the following manual fixes:

  • HedSchema and HedSchemas were renamed to Schema and Schemas, to match the hed-javascript v4 API.
  • I added placeholder getters to Schema for fields which were removed in the new implementation, as there was no easy way to restore the functionality and the data is useless anyway.
  • The schema-related type information is now imported from the auto-generated type declaration files.
  • I copied several unmerged schemas from the TypeScript code.
  • The schema config was left unchanged, as the TypeScript code still uses the old require-based code and I didn't want it to go backwards.

I simply decided to copy over the tsc compilation of the TypeScript
code rather than do anything manual. I had to make the following
manual fixes:

- HedSchema and HedSchemas were renamed to Schema and Schemas, to
  match the hed-javascript v4 API.
- I added placeholder getters to Schema for fields which were removed
  in the new implementation, as there was no easy way to restore the
  functionality and the data is useless anyway.
- The schema-related type information is now imported from the
  auto-generated type declaration files.
- I copied several unmerged schemas from the TypeScript code.
@happy5214 happy5214 requested a review from VisLab June 20, 2026 21:39
@happy5214 happy5214 self-assigned this Jun 20, 2026
@happy5214 happy5214 added enhancement New feature or request tests Issues related to testcases schema Schema parsing types labels Jun 20, 2026
@qltysh

qltysh Bot commented Jun 20, 2026

Copy link
Copy Markdown

❌ 7 blocking issues (7 total)

Tool Category Rule Count
eslint Lint Definition for rule '@typescript-eslint/no-unused-vars' was not found. 2
eslint Lint 'attributeName' is defined but never used. 2
radarlint-js Lint Unexpected empty method '_addCustomEntries'. 2
radarlint-js Lint Complete the task associated to this "TODO" comment. 1

* @param attributeName - The attribute to check for.
* @returns Whether this schema entry has this attribute.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definition for rule '@typescript-eslint/no-unused-vars' was not found. [eslint:@typescript-eslint/no-unused-vars]

* @returns Whether this schema entry has this attribute.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasBooleanAttribute(attributeName) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'attributeName' is defined but never used. [eslint:no-unused-vars]

Suggested change
hasBooleanAttribute(attributeName) {
hasBooleanAttribute() {

Remove unused variable 'attributeName'.

return false
}
}
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many returns (count = 6): equivalent [qlty:return-statements]

Comment thread src/schema/entries/tag.js
* @param unitClasses - The unit classes for this tag.
* @param valueClasses - The value classes for this tag.
*/
constructor(name, parentTag, booleanAttributes, valueAttributes, unitClasses, valueClasses) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many parameters (count = 6): constructor [qlty:function-parameters]

Comment thread src/schema/entries/tag.js
if (this.valueTag === undefined && other.valueTag !== undefined) {
return false
}
return !(this.valueTag && !this.valueTag.equivalent(other.valueTag))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many returns (count = 6): equivalent [qlty:return-statements]

* @param unitClasses - The unit classes for this tag.
* @param valueClasses - The value classes for this tag.
*/
constructor(name, parentTag, booleanAttributes, valueAttributes, unitClasses, valueClasses) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many parameters (count = 6): constructor [qlty:function-parameters]

/**
* Add any custom entries required by the platform to support old versions.
*/
_addCustomEntries() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method '_addCustomEntries'. [radarlint-js:javascript:S1186]

this.addEntry(name, this._buildEntry(name, booleanAttributes, valueAttributes))
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definition for rule '@typescript-eslint/no-unused-vars' was not found. [eslint:@typescript-eslint/no-unused-vars]

}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_preprocessSchema(schemaXml) {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. Unexpected empty method '_preprocessSchema'. [radarlint-js:javascript:S1186]


2. 'schemaXml' is defined but never used. [eslint:no-unused-vars]

Suggested change
_preprocessSchema(schemaXml) {}
_preprocessSchema() {}

Remove unused variable 'schemaXml'.

Comment thread src/schema/parser/tag.js
})
.filter((valueClass) => valueClass !== undefined) ?? []
tagValueClassDefinitions.set(tagName, tagValueClasses)
// TODO: Uncomment once value validation uses value classes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. Complete the task associated to this "TODO" comment. [radarlint-js:javascript:S1135]


2. // TODO: Uncomment once value validation uses value classes. [ripgrep:TODO]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports the newer TypeScript-based schema parsing/merging implementation into the JavaScript codebase, refactoring schema loading and parsing into a loader + parser pipeline and updating tests/fixtures and exported type definitions accordingly.

Changes:

  • Replaced the legacy monolithic schema parser/partnered-schema merger with a new AbstractHedSchemaLoader + per-entry parser architecture.
  • Split schema “entries” into individual modules (tags/units/value classes/etc.) and introduced XML collection/types to support merged/unmerged schema inputs.
  • Updated schema-related tests and XML fixtures (including new “unmerged” library schemas) and adjusted TypeScript declarations to reference the new implementation.

Reviewed changes

Copilot reviewed 41 out of 79 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
types/index.d.ts Replaced inline schema type declarations with re-exports from the new schema implementation modules.
tests/otherTests/schema.spec.js Updated schema loading/merging tests for the new loader/parser behavior and new unmerged fixtures.
tests/otherTestData/unmerged/HED8.2.0.xml Updated standard schema fixture content/metadata to match the new parsing expectations (and removed old test-only nodes).
tests/otherTestData/unmerged/HED8.1.0.xml Updated schema fixture content to align with new schema format/sections and revised descriptions/attributes.
tests/otherTestData/unmerged/HED_testlib_2.0.0.xml Added unmerged library schema fixture used for partnered/merge-conflict testing.
tests/otherTestData/unmerged/HED_testlib_2.1.0.xml Added unmerged library schema fixture used for partnered/merge-conflict testing.
tests/otherTestData/unmerged/HED_testlib_3.0.0.xml Added unmerged library schema fixture used for partnered/merge-conflict testing.
tests/jsonTests/tagParserTests.spec.js Updated imports to match the new SchemaValueTag module location.
tests/jsonTestData/schemaBuildTests.data.js Updated expected issue payloads and conflict tag names for the new schema build logic.
src/utils/xml.js Ensured parsed schema XML nodes have $parent pointers via setParent() during parseSchemaXML().
src/schema/xmlType.js Added XML collection container and helper for extracting element names.
src/schema/xmlType.d.ts Added TypeScript declarations for parsed schema XML shapes and XML collection container.
src/schema/specs.js Refined schema spec parsing/deduping and tightened validation for version spec inputs.
src/schema/specs.d.ts Added TypeScript declarations for SchemaSpec/SchemasSpec.
src/schema/schemaMerger.js Removed legacy partnered-schema merger implementation.
src/schema/parser/valueClass.js Added value class parser using classRegex.json to construct value validation regexes.
src/schema/parser/valueClass.d.ts Added declarations for value class parser.
src/schema/parser/unitModifier.js Added unit modifier parser.
src/schema/parser/unitModifier.d.ts Added declarations for unit modifier parser.
src/schema/parser/unitClass.js Added unit class + per-unit parsing with duplicate checks across merged inputs.
src/schema/parser/unitClass.d.ts Added declarations for unit class parser.
src/schema/parser/tag.js Added tag parser (including rooted tags, recursive attributes, unit/value class bindings, and duplicate detection).
src/schema/parser/tag.d.ts Added declarations for tag parser.
src/schema/parser/schemaParser.js Added orchestrating schema parser that runs property/attribute/unit/value/tag parsers.
src/schema/parser/schemaParser.d.ts Added declarations for schema parser.
src/schema/parser/schemaEntry.js Added generic parser base classes for schema entries and schema entries-with-attributes.
src/schema/parser/schemaEntry.d.ts Added declarations for schema entry parser base classes.
src/schema/parser/property.js Added schema property parser, including injection of compatibility properties for older schemas.
src/schema/parser/property.d.ts Added declarations for property parser.
src/schema/parser/attribute.js Added schema attribute parser and recursion inference logic.
src/schema/parser/attribute.d.ts Added declarations for attribute parser.
src/schema/parser.js Removed legacy schema parser implementation.
src/schema/loader.js Replaced function-based loader with HedSchemaLoader class implementation for Node environments.
src/schema/loader.d.ts Added declarations for HedSchemaLoader.
src/schema/init.js Deprecated the old buildSchemas* functions and delegated to HedSchemaLoader.
src/schema/init.d.ts Added declarations for deprecated init functions.
src/schema/entries/valueTag.js Added explicit SchemaValueTag class module with equivalence logic.
src/schema/entries/valueTag.d.ts Added declarations for SchemaValueTag.
src/schema/entries/valueClass.js Added explicit SchemaValueClass class module with value validation logic.
src/schema/entries/valueClass.d.ts Added declarations for SchemaValueClass.
src/schema/entries/unitModifier.js Added explicit SchemaUnitModifier class module.
src/schema/entries/unitModifier.d.ts Added declarations for SchemaUnitModifier.
src/schema/entries/unitClass.js Added explicit SchemaUnitClass class module (including default unit and unit extraction).
src/schema/entries/unitClass.d.ts Added declarations for SchemaUnitClass.
src/schema/entries/unit.js Added explicit SchemaUnit class module (derivatives, SI modifiers, prefix units).
src/schema/entries/unit.d.ts Added declarations for SchemaUnit.
src/schema/entries/tag.js Added explicit SchemaTag class module (parent/valueTag handling, naming, equivalence).
src/schema/entries/tag.d.ts Added declarations for SchemaTag.
src/schema/entries/schemaEntryWithAttributes.js Added explicit base class for schema entries that carry boolean/value attributes.
src/schema/entries/schemaEntryWithAttributes.d.ts Added declarations for SchemaEntryWithAttributes.
src/schema/entries/schemaEntryManager.js Added explicit SchemaEntryManager module (iteration/filtering helpers).
src/schema/entries/schemaEntryManager.d.ts Added declarations for SchemaEntryManager.
src/schema/entries/schemaEntry.js Added explicit SchemaEntry base class module.
src/schema/entries/schemaEntry.d.ts Added declarations for SchemaEntry.
src/schema/entries/schemaEntries.js Added explicit SchemaEntries container module.
src/schema/entries/schemaEntries.d.ts Added declarations for SchemaEntries.
src/schema/entries/property.js Added explicit SchemaProperty class module.
src/schema/entries/property.d.ts Added declarations for SchemaProperty.
src/schema/entries/attribute.js Added explicit SchemaAttribute class module (properties + recursion flag).
src/schema/entries/attribute.d.ts Added declarations for SchemaAttribute.
src/schema/entries.js Removed legacy “all entries in one file” implementation.
src/schema/containers.js Updated Schema/Schemas containers for the new merged-XML approach (deprecated legacy getters).
src/schema/containers.d.ts Added declarations for schema containers.
src/schema/config.js Minor doc/header cleanup for bundled schema config.
src/schema/config.d.ts Added declarations for bundled schema config exports.
src/schema/abstractLoader.js Added loader superclass implementing build/merge rules for standard+library schemas.
src/schema/abstractLoader.d.ts Added declarations for abstract loader.
src/parser/parsedHedTag.js Updated import to the new SchemaValueTag module.
Comments suppressed due to low confidence (1)

tests/otherTestData/unmerged/HED8.1.0.xml:5628

  • The description text is missing the opening parenthesis, making the example inconsistent with surrounding relation descriptions.

Comment thread src/schema/parser/tag.js
Comment on lines +194 to +198
for (const childTag of this.getAllChildTags(tagElement)) {
const childTagName = getElementTagName(childTag)
const newBooleanAttributes =
booleanAttributeDefinitions.get(childTagName)?.union(recursiveAttributes) ?? new Set()
booleanAttributeDefinitions.set(childTagName, newBooleanAttributes)
Comment on lines +81 to +85
if (standardVersions.size !== 1) {
IssueError.generateAndThrow('differentWithStandard', {
versions: JSON.stringify(Array.from(standardVersions).toSorted((a, b) => a.localeCompare(b))),
})
}
Comment on lines +158 to +160
schemaError: new IssueError(
generateIssue('differentWithStandard', { versions: JSON.stringify(['8.2.0', '8.3.0']) }),
),
Comment thread src/schema/entries/tag.js
Comment on lines +141 to +158
equivalent(other) {
if (!(other instanceof SchemaTag)) {
return false
}
if (!super.equivalent(other)) {
return false
}
if (this.parent === undefined && other.parent !== undefined) {
return false
}
if (this.parent && !this.parent.equivalent(other.parent)) {
return false
}
if (this.valueTag === undefined && other.valueTag !== undefined) {
return false
}
return !(this.valueTag && !this.valueTag.equivalent(other.valueTag))
}
Comment thread tests/otherTests/schema.spec.js Outdated
Comment on lines 333 to 337
const schemas = await buildSchemas(specs2)
assert.instanceOf(
assert.isNotNull(
schemas.getSchema('testlib'),
PartneredSchema,
'Parsed testlib schema (combined 2.0.0 and 3.0.0) is not an instance of PartneredSchema',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request schema Schema parsing tests Issues related to testcases types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants