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.
Functionalities
- generate typescript interface each object class
- generate enum for supported controls, capabilities, extensions, policies
- generate relations between classes in json format
- generate graphql type for each object class
- generate graphql basic CRUD resolvers for each object class
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;
"msDS-ObjectReference"?: 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