@the-software-compagny/parser_ldap_rfc4512 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -0
- package/README.md +149 -0
- package/cli.js +13107 -0
- package/index.js +8089 -0
- package/package.json +48 -0
package/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2024, The Software Compagny
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# RFC 4512 LDAP Schema Parser
|
2
|
+
|
3
|
+
[](https://github.com/The-Software-Compagny/parser_ldap_rfc4512/actions/workflows/ci.yml)
|
4
|
+
[](https://codecov.io/gh/The-Software-Compagny/parser_ldap_rfc4512)
|
5
|
+
[](https://badge.fury.io/js/@the-software-compagny%2Fparser_ldap_rfc4512)
|
6
|
+
|
7
|
+
A TypeScript parser for LDAP schema definitions based on RFC 4512, using PEG.js grammar.
|
8
|
+
|
9
|
+
## Overview
|
10
|
+
|
11
|
+
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).
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
- **RFC 4512 Compliance**: Follows the official LDAP schema definition format
|
16
|
+
- **PEG.js Grammar**: Uses a robust parsing expression grammar for accurate parsing
|
17
|
+
- **TypeScript Support**: Written in TypeScript with proper type definitions
|
18
|
+
- **Object Class Parsing**: Supports STRUCTURAL, AUXILIARY, and ABSTRACT object classes
|
19
|
+
- **Attribute Lists**: Handles both required (MUST) and optional (MAY) attribute lists
|
20
|
+
- **Multiple Names**: Supports single and multiple NAME definitions
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
To install dependencies:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
bun install
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
### As a Library
|
33
|
+
|
34
|
+
```typescript
|
35
|
+
import { parseSchema } from '@the-software-compagny/parser_ldap_rfc4512'
|
36
|
+
|
37
|
+
const result = parseSchema(`
|
38
|
+
( 2.5.6.6
|
39
|
+
NAME 'person'
|
40
|
+
DESC 'RFC2256: a person'
|
41
|
+
SUP top
|
42
|
+
STRUCTURAL
|
43
|
+
MUST ( sn $ cn )
|
44
|
+
MAY ( userPassword $ telephoneNumber )
|
45
|
+
)
|
46
|
+
`)
|
47
|
+
|
48
|
+
if (result.success) {
|
49
|
+
console.log('Parsed schema:', result.data)
|
50
|
+
} else {
|
51
|
+
console.error('Parse error:', result.error)
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
55
|
+
### As a CLI Tool
|
56
|
+
|
57
|
+
This package includes a command-line interface for parsing LDAP schema definitions.
|
58
|
+
|
59
|
+
#### Installation
|
60
|
+
|
61
|
+
```bash
|
62
|
+
# Install globally
|
63
|
+
npm install -g @the-software-compagny/parser_ldap_rfc4512
|
64
|
+
|
65
|
+
# Or use locally after building
|
66
|
+
bun run build
|
67
|
+
```
|
68
|
+
|
69
|
+
#### CLI Usage
|
70
|
+
|
71
|
+
```bash
|
72
|
+
# Parse from command line
|
73
|
+
rfc4512-parser "( 2.5.6.6 NAME 'person' SUP top STRUCTURAL )"
|
74
|
+
|
75
|
+
# Parse from file
|
76
|
+
rfc4512-parser --input schema.ldif
|
77
|
+
|
78
|
+
# Output as JSON
|
79
|
+
rfc4512-parser --input schema.ldif --format json
|
80
|
+
|
81
|
+
# Save to file
|
82
|
+
rfc4512-parser --input schema.ldif --output result.json
|
83
|
+
|
84
|
+
# Verbose mode
|
85
|
+
rfc4512-parser --input schema.ldif --verbose
|
86
|
+
```
|
87
|
+
|
88
|
+
[CLI Usage](CLI_USAGE.md) provides detailed instructions on how to use the command-line interface, including installation and examples.
|
89
|
+
|
90
|
+
### Example Schema Definition
|
91
|
+
|
92
|
+
The parser can handle LDAP schema definitions like this:
|
93
|
+
|
94
|
+
```ldap
|
95
|
+
( 2.5.6.6
|
96
|
+
NAME 'person'
|
97
|
+
DESC 'RFC2256: a person'
|
98
|
+
SUP top
|
99
|
+
STRUCTURAL
|
100
|
+
MUST ( sn $ cn )
|
101
|
+
MAY ( userPassword $ telephoneNumber )
|
102
|
+
)
|
103
|
+
```
|
104
|
+
|
105
|
+
This will be parsed into a structured object:
|
106
|
+
|
107
|
+
```javascript
|
108
|
+
{
|
109
|
+
oid: '2.5.6.6',
|
110
|
+
name: 'person',
|
111
|
+
desc: 'RFC2256: a person',
|
112
|
+
sup: 'top',
|
113
|
+
type: 'STRUCTURAL',
|
114
|
+
must: ['sn', 'cn'],
|
115
|
+
may: ['userPassword', 'telephoneNumber']
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
119
|
+
## Project Structure
|
120
|
+
|
121
|
+
```bash
|
122
|
+
.
|
123
|
+
├── .vscode/ # VS Code workspace settings and tasks configuration
|
124
|
+
├── dist/ # Build output directory containing compiled JavaScript files
|
125
|
+
├── src/ # Source code directory
|
126
|
+
│ ├── _grammars/ # PEG.js grammar definitions for parsing RFC 4512
|
127
|
+
│ ├── errors/ # Error handling classes, interfaces and enumerations
|
128
|
+
│ ├── functions/ # Utility functions including the main schema parsing logic
|
129
|
+
│ ├── interfaces/ # TypeScript interfaces for LDAP schema components
|
130
|
+
│ └── types/ # TypeScript type definitions for LDAP structures
|
131
|
+
├── test/ # Test files and test data
|
132
|
+
└── [configuration files] # Various config files (.editorconfig, .eslintrc.js, etc.)
|
133
|
+
```
|
134
|
+
|
135
|
+
## Grammar Components
|
136
|
+
|
137
|
+
The PEG.js grammar supports the following LDAP schema components:
|
138
|
+
|
139
|
+
- **OID**: Numeric object identifier (e.g., `2.5.6.6`)
|
140
|
+
- **NAME**: Single or multiple names in quotes
|
141
|
+
- **DESC**: Description string
|
142
|
+
- **SUP**: Superior object class or attribute type
|
143
|
+
- **Object Class Types**: STRUCTURAL, AUXILIARY, or ABSTRACT
|
144
|
+
- **MUST**: Required attributes list
|
145
|
+
- **MAY**: Optional attributes list
|
146
|
+
|
147
|
+
## License
|
148
|
+
|
149
|
+
See [LICENSE](LICENSE) file for details.
|