Port TypeScript reimplementation of schema parsing to JavaScript#766
Open
happy5214 wants to merge 3 commits into
Open
Port TypeScript reimplementation of schema parsing to JavaScript#766happy5214 wants to merge 3 commits into
happy5214 wants to merge 3 commits into
Conversation
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.
❌ 7 blocking issues (7 total)
|
| * @param attributeName - The attribute to check for. | ||
| * @returns Whether this schema entry has this attribute. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| * @returns Whether this schema entry has this attribute. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| hasBooleanAttribute(attributeName) { |
| return false | ||
| } | ||
| } | ||
| return true |
| * @param unitClasses - The unit classes for this tag. | ||
| * @param valueClasses - The value classes for this tag. | ||
| */ | ||
| constructor(name, parentTag, booleanAttributes, valueAttributes, unitClasses, valueClasses) { |
| if (this.valueTag === undefined && other.valueTag !== undefined) { | ||
| return false | ||
| } | ||
| return !(this.valueTag && !this.valueTag.equivalent(other.valueTag)) |
| * @param unitClasses - The unit classes for this tag. | ||
| * @param valueClasses - The value classes for this tag. | ||
| */ | ||
| constructor(name, parentTag, booleanAttributes, valueAttributes, unitClasses, valueClasses) { |
| /** | ||
| * Add any custom entries required by the platform to support old versions. | ||
| */ | ||
| _addCustomEntries() {} |
| this.addEntry(name, this._buildEntry(name, booleanAttributes, valueAttributes)) | ||
| } | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| } | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| _preprocessSchema(schemaXml) {} |
There was a problem hiding this comment.
| }) | ||
| .filter((valueClass) => valueClass !== undefined) ?? [] | ||
| tagValueClassDefinitions.set(tagName, tagValueClasses) | ||
| // TODO: Uncomment once value validation uses value classes. |
Contributor
There was a problem hiding this comment.
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 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 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 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', | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
require-based code and I didn't want it to go backwards.