-
Notifications
You must be signed in to change notification settings - Fork 0
/
initial.ts
75 lines (69 loc) · 2.19 KB
/
initial.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {
generateInterfaceFiles,
getSchemaAttributes,
getSchemaClasses,
getCountryIsoCodes,
generateCountryIsoCodesFile,
} from "ldap-schema-ts-generator";
import { Logger } from "fast-node-logger";
import { variables } from "./variables";
import { Client } from "ldap-ts-client";
type InitOptions = {
client: Client;
options?: {
/** generate schema interface. default true */
generateInterfaces?: boolean;
/** use cached interfaces if exist. default true. if set false regenerate interfaces */
useCachedInterfaces?: boolean;
/** instance of Logger mostly used in tracing */
logger?: Logger;
/** generate country iso-3166 codes. default false */
generateCountryIsoCodes?: boolean;
};
};
/** this is necessary to run this function first time you want to use the library. it does:
* 1. generate interface files from ldap schema
* @returns location of generated files
*/
export async function initial({ client, options }: InitOptions) {
/**@step set defaults */
/** */
let generateInterfaces = true;
if (typeof options?.generateInterfaces === "boolean") {
generateInterfaces = options?.generateInterfaces;
}
let useCachedInterfaces = true;
if (typeof options?.useCachedInterfaces === "boolean") {
useCachedInterfaces = options?.useCachedInterfaces;
}
let generateCountryIsoCodes = false;
if (typeof options?.generateCountryIsoCodes === "boolean") {
generateCountryIsoCodes = options?.generateCountryIsoCodes;
}
if (generateInterfaces) {
if (!useCachedInterfaces) {
const objectAttributes = await getSchemaAttributes({
client,
options: { logger: options?.logger },
});
const objectClasses = await getSchemaClasses({
client,
options: { logger: options?.logger },
});
await generateInterfaceFiles({
objectAttributes,
objectClasses,
options: {
outputFolder: variables.defaultInterfaceDir,
},
});
}
}
if (generateCountryIsoCodes) {
const countryCodes = await getCountryIsoCodes({ useCache: true });
await generateCountryIsoCodesFile({
countryCodes,
options: { outDir: variables.defaultJsonDir },
});
}
}