A TypeScript parser for LDAP schema definitions based on RFC 4512, using PEG.js grammar.
This project provides a parser for LDAP (Lightweight Directory Access Protocol) schema definitions according to RFC 4512. It can parse 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).
- RFC 4512 Compliance: Follows the official LDAP schema definition format
- PEG.js Grammar: Uses a robust parsing expression grammar for accurate parsing
- TypeScript Support: Written in TypeScript with proper type definitions
- Object Class Parsing: Supports STRUCTURAL, AUXILIARY, and ABSTRACT object classes
- Attribute Lists: Handles both required (MUST) and optional (MAY) attribute lists
- Multiple Names: Supports single and multiple NAME definitions
To install dependencies:
bun installimport { parseSchema } from '@the-software-compagny/parser_ldap_rfc4512'
const result = parseSchema(`
( 2.5.6.6
NAME 'person'
DESC 'RFC2256: a person'
SUP top
STRUCTURAL
MUST ( sn $ cn )
MAY ( userPassword $ telephoneNumber )
)
`)
if (result.success) {
console.log('Parsed schema:', result.data)
} else {
console.error('Parse error:', result.error)
}This package includes a command-line interface for parsing LDAP schema definitions.
# Install globally
npm install -g @the-software-compagny/parser_ldap_rfc4512
# Or use locally after building
bun run build# Parse from command line
rfc4512-parser "( 2.5.6.6 NAME 'person' SUP top STRUCTURAL )"
# Parse from file
rfc4512-parser --input schema.ldif
# Output as JSON
rfc4512-parser --input schema.ldif --format json
# Save to file
rfc4512-parser --input schema.ldif --output result.json
# Verbose mode
rfc4512-parser --input schema.ldif --verboseCLI Usage provides detailed instructions on how to use the command-line interface, including installation and examples.
The parser can handle LDAP schema definitions like this:
( 2.5.6.6
NAME 'person'
DESC 'RFC2256: a person'
SUP top
STRUCTURAL
MUST ( sn $ cn )
MAY ( userPassword $ telephoneNumber )
)
This will be parsed into a structured object:
{
oid: '2.5.6.6',
name: 'person',
desc: 'RFC2256: a person',
sup: 'top',
type: 'STRUCTURAL',
must: ['sn', 'cn'],
may: ['userPassword', 'telephoneNumber']
}.
├── .vscode/ # VS Code workspace settings and tasks configuration
├── dist/ # Build output directory containing compiled JavaScript files
├── src/ # Source code directory
│ ├── _grammars/ # PEG.js grammar definitions for parsing RFC 4512
│ ├── errors/ # Error handling classes, interfaces and enumerations
│ ├── functions/ # Utility functions including the main schema parsing logic
│ ├── interfaces/ # TypeScript interfaces for LDAP schema components
│ └── types/ # TypeScript type definitions for LDAP structures
├── test/ # Test files and test data
└── [configuration files] # Various config files (.editorconfig, .eslintrc.js, etc.)The PEG.js grammar supports the following LDAP schema components:
- OID: Numeric object identifier (e.g.,
2.5.6.6) - NAME: Single or multiple names in quotes
- DESC: Description string
- SUP: Superior object class or attribute type
- Object Class Types: STRUCTURAL, AUXILIARY, or ABSTRACT
- MUST: Required attributes list
- MAY: Optional attributes list
See LICENSE file for details.