A robust TypeScript parser for LDAP schema definitions based on RFC 4512, featuring a complete CLI tool and comprehensive parsing capabilities using PEG.js grammar.
This project provides a comprehensive parser for LDAP (Lightweight Directory Access Protocol) schema definitions according to RFC 4512. It can parse both object class and attribute type definitions with their various components such as OID, NAME, DESC, SUP, MUST, MAY, and object class types (STRUCTURAL, AUXILIARY, ABSTRACT). The parser comes with both a programmatic TypeScript API and a powerful command-line interface.
- Full RFC 4512 Compliance: Strictly follows the official LDAP schema definition format
- OpenLDAP cn=config Support: Automatically handles OpenLDAP index prefixes like
{57}
- Object Class Parsing: Complete support for STRUCTURAL, AUXILIARY, and ABSTRACT object classes
- Attribute Type Parsing: Comprehensive parsing of attribute types with all their properties
- OID Validation: Robust validation of numeric object identifiers
- Multiple Names Support: Handles single and multiple NAME definitions seamlessly
- Global Command:
rfc4512-parser
command available system-wide after installation - Multiple Input Sources: Parse from command line arguments or LDIF files
- Flexible Output Formats: Support for JSON, structured text, and custom formatting
- Verbose Mode: Detailed parsing information for debugging and analysis
- Error Reporting: Comprehensive error messages with line and column information
- TypeScript First: Written in TypeScript with complete type definitions
- Robust Grammar: Uses PEG.js for precise and reliable parsing
- Error Handling: Detailed error system with exact error location
- Simple Integration: Easy-to-use
parseSchema()
function - Module Support: Compatible with both ESM and CommonJS environments
- Comprehensive Testing: ~100% test coverage with real-world LDAP schemas
- CI/CD Pipeline: Automated testing with GitHub Actions
- Performance Optimized: Built with Bun for optimal performance
- Well Documented: Complete documentation with practical examples
# Install as a library
npm install @the-software-compagny/parser_ldap_rfc4512
# Or with Bun
bun add @the-software-compagny/parser_ldap_rfc4512
# Install globally for CLI usage
npm install -g @the-software-compagny/parser_ldap_rfc4512
import { parseSchema } from '@the-software-compagny/parser_ldap_rfc4512'
// Parse an object class definition
try {
const result = parseSchema(`
( 2.5.6.6
NAME 'person'
DESC 'RFC2256: a person'
SUP top
STRUCTURAL
MUST ( sn $ cn )
MAY ( userPassword $ telephoneNumber $ description )
)
`)
console.log('β
Successfully parsed:', result)
// Output:
// {
// oid: '2.5.6.6',
// name: 'person',
// desc: 'RFC2256: a person',
// sup: 'top',
// type: 'STRUCTURAL',
// must: ['sn', 'cn'],
// may: ['userPassword', 'telephoneNumber', 'description']
// }
} catch (error) {
console.error('β Parse error:', error.message)
}
The CLI provides a powerful way to parse LDAP schemas directly from the terminal.
# Parse a schema definition directly
rfc4512-parser "( 2.5.6.6 NAME 'person' SUP top STRUCTURAL )"
# Parse from a file
rfc4512-parser --input schema.ldif
# Output as formatted JSON
rfc4512-parser --input schema.ldif --format json
# Save results to a file
rfc4512-parser --input schema.ldif --output parsed-schema.json
# Verbose mode with detailed information
rfc4512-parser --input schema.ldif --verbose
# Parse multiple schema definitions from a file
rfc4512-parser --input multiple-schemas.ldif --format json
# Validate schema syntax without output
rfc4512-parser --input schema.ldif --validate-only
# Parse with custom error formatting
rfc4512-parser --input schema.ldif --verbose --format json
π For complete CLI documentation, see CLI_USAGE.md
The parser handles all RFC 4512 object class components:
- OID: Numeric object identifier (e.g.,
2.5.6.6
) - NAME: Single name (
'person'
) or multiple names (( 'person' 'user' )
) - DESC: Descriptive text in quotes
- SUP: Superior object class (inheritance)
- Object Class Types:
STRUCTURAL
- Standard object classesAUXILIARY
- Additional attribute setsABSTRACT
- Base classes for inheritance
- MUST: Required attributes list
- MAY: Optional attributes list
Complete support for attribute type definitions:
- OID: Unique numeric identifier
- NAME: Single or multiple attribute names
- DESC: Human-readable description
- SUP: Superior attribute type
- EQUALITY: Equality matching rule
- ORDERING: Ordering matching rule
- SUBSTR: Substring matching rule
- SYNTAX: Attribute syntax OID
- SINGLE-VALUE: Single value constraint
- COLLECTIVE: Collective attribute marker
- NO-USER-MODIFICATION: System-only attributes
( 2.5.6.7
NAME ( 'organizationalPerson' 'orgPerson' )
DESC 'RFC2256: an organizational person'
SUP person
STRUCTURAL
MAY ( title $ x121Address $ registeredAddress $ destinationIndicator $
preferredDeliveryMethod $ telexNumber $ teletexTerminalIdentifier $
telephoneNumber $ internationaliSDNNumber $ facsimileTelephoneNumber $
street $ postOfficeBox $ postalCode $ postalAddress $
physicalDeliveryOfficeName $ ou $ st $ l )
)
( 2.5.4.3
NAME ( 'cn' 'commonName' )
DESC 'RFC2256: common name(s) for which the entity is known by'
SUP name
)
The parser includes built-in support for OpenLDAP's cn=config
format, which uses index prefixes to maintain ordering of multi-valued attributes like olcAttributeTypes
and olcObjectClasses
.
OpenLDAP uses numeric prefixes in curly braces to maintain the order of schema definitions:
# OpenLDAP cn=config format with index prefix
{57}( 1.3.6.1.4.1.7165.2.1.80 NAME 'sambaSupportedEncryptionTypes'
DESC 'Supported encryption types of a trust'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE )
# Equivalent RFC 4512 pure format (without prefix)
( 1.3.6.1.4.1.7165.2.1.80 NAME 'sambaSupportedEncryptionTypes'
DESC 'Supported encryption types of a trust'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE )
The parser automatically detects and removes OpenLDAP index prefixes:
import { parseSchema } from '@the-software-compagny/parser_ldap_rfc4512'
// Both formats parse to identical results
const openLdapFormat = '{57}( 2.5.4.3 NAME \'cn\' DESC \'Common Name\' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )'
const rfc4512Format = '( 2.5.4.3 NAME \'cn\' DESC \'Common Name\' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )'
const result1 = parseSchema(openLdapFormat)
const result2 = parseSchema(rfc4512Format)
console.log(result1 === result2) // true - identical results
The parser handles various OpenLDAP prefix formats:
- Basic format:
{0}
,{57}
,{123}
- With whitespace:
{0}
,\t{57}\t
- Leading spaces:
{0}(definition...)
- Any numeric index:
{0}
to{99999}
and beyond
The CLI tool seamlessly handles OpenLDAP exports:
# Parse OpenLDAP cn=config exports directly
rfc4512-parser --input openldap-export.ldif --format json
# Example OpenLDAP export file content:
# {0}( 2.5.4.3 NAME 'cn' DESC 'Common Name' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
# {1}( 2.5.4.4 NAME 'sn' DESC 'Surname' SUP name )
.
βββ .github/ # GitHub workflows and CI/CD configuration
β βββ workflows/ # Automated testing and build pipelines
βββ .vscode/ # VS Code workspace settings and tasks
βββ dist/ # Compiled output (generated)
βββ src/ # Source code
β βββ _grammars/ # PEG.js grammar definitions
β βββ errors/ # Error handling system
β βββ functions/ # Core parsing logic
β βββ interfaces/ # TypeScript interfaces
β βββ types/ # Type definitions
βββ test/ # Comprehensive test suite
.
- PEG.js Parser: Uses Parsing Expression Grammar for precise, unambiguous parsing
- Error Recovery: Provides detailed error messages with line and column information
- Whitespace Handling: Robust handling of LDAP schema formatting variations
- Performance: Optimized grammar rules for fast parsing of large schema files
- Strict TypeScript: Complete type coverage for all LDAP components
- Interface-Driven: Well-defined interfaces for extensibility
- Error Types: Comprehensive error type system for debugging
- Runtime Validation: Schema validation beyond syntax checking
- Bun Runtime: Fast JavaScript runtime for optimal performance
- Tree Shaking: Optimized builds with unused code elimination
- Dual Output: Both ESM and CommonJS compatible builds
- CLI Bundling: Self-contained CLI executable
- Unit Tests: Complete coverage of all parsing components
- Integration Tests: End-to-end testing with real LDAP schemas
- CLI Tests: Command-line interface testing with various scenarios
- Error Handling Tests: Comprehensive error condition testing
- OpenLDAP Schemas: Tested against actual OpenLDAP schema definitions
- RFC Compliance: Validated against RFC 4512 specifications
- Edge Cases: Extensive testing of formatting variations and edge cases
- Code Coverage: ~100% test coverage on core components
- CI/CD: Automated testing on multiple Node.js versions
- Code Quality: ESLint and Prettier for consistent code style
- Performance: Benchmarked against large schema files
We welcome contributions! Please see our contributing guidelines for details on:
- Setting up the development environment
- Running tests and building the project
- Code style and formatting requirements
- Submitting pull requests
# Clone the repository
git clone https://github.com/The-Software-Compagny/parser_ldap_rfc4512.git
cd parser_ldap_rfc4512
# Install dependencies
bun install
# Run tests
bun test
# Build the project
bun run build
# Test CLI locally
bun run test:cli
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
- NPM Package: @the-software-compagny/parser_ldap_rfc4512
- GitHub Repository: parser_ldap_rfc4512
- Issue Tracker: GitHub Issues
- CI/CD Pipeline: GitHub Actions
- Code Coverage: Codecov
Made with β€οΈ by The Software Compagny