Typescript typedef and meta-data generator for LDAP Schema
It can be useful to interact from schema-aware/type-safe LDAP Client with LDAP servers like active directory.
How to use
npm i ldap-schema-ts-generator
import {
getSchemaAttributes,
getSchemaClasses,
generateInterfaceFiles,
} from "ldap-schema-ts-generator";
const options = {
user: "**********",
pass: "************",
ldapServerUrl: "ldap://domain.com",
};
const schemaDn = await getSchemaNamingContext({ options });
const objectAttributes = await getSchemaAttributes({ schemaDn, options });
const objectClasses = await getSchemaClasses({ schemaDn, options });
await generateInterfaceFiles({ objectAttributes, objectClasses });
}
Options:
options?: {
outputFolder?: string;
usePrettier?: boolean;
indexFile: boolean;
};
API
use api website for more details
Result
creates typescript interface for each LDAP class that exist in schema
Sample Generated File:
import { Top } from "./Top";
import { MsExchBaseClass } from "./MsExchBaseClass";
export interface Container extends Top, MsExchBaseClass {
readonly cn: string;
x500RDN?: string;
msExchTemplateRDNs?: string[];
msExchPolicyList?: object[];
containerInfo?: number;
msExchExportContainersBL?: object;
"msDS-ObjectReference"?: object[];
readonly schemaVersion?: number[];
readonly defaultClassStore?: object[];
}
TODO:
Know Issues
- when extends to another interface sometimes a field is optional but in other interface is not so typescript gives compatibility warning which prevent generated code to be executed with typescript complier. to fix the problem an extra comment
// @ts-ignore
added in top of all generated interfaces
Credit