feat(server): sql access checks (#6635)

This commit is contained in:
Jason Rasmussen 2024-01-25 10:14:38 -05:00 committed by GitHub
parent bd87eb309c
commit 7fc4abba72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 760 additions and 418 deletions

View file

@ -98,8 +98,25 @@ class SqlGenerator {
const data: string[] = [`-- NOTE: This file is auto generated by ./sql-generator`];
const instance = this.app.get<Repository>(Repository);
const properties = Object.getOwnPropertyNames(Repository.prototype) as Array<keyof typeof Repository>;
for (const key of properties) {
// normal repositories
data.push(...(await this.runTargets(instance, `${Repository.name}`)));
// nested repositories
if (Repository.name === AccessRepository.name) {
for (const key of Object.keys(instance)) {
const subInstance = (instance as any)[key];
data.push(...(await this.runTargets(subInstance, `${Repository.name}.${key}`)));
}
}
this.results[Repository.name] = data;
}
private async runTargets(instance: any, label: string) {
const data: string[] = [];
for (const key of this.getPropertyNames(instance)) {
const target = instance[key];
if (!(target instanceof Function)) {
continue;
@ -116,7 +133,7 @@ class SqlGenerator {
}
for (const { name, params } of queries) {
let queryLabel = `${Repository.name}.${key}`;
let queryLabel = `${label}.${key}`;
if (name) {
queryLabel += ` (${name})`;
}
@ -135,7 +152,7 @@ class SqlGenerator {
}
}
this.results[Repository.name] = data;
return data;
}
private async write() {
@ -156,6 +173,10 @@ class SqlGenerator {
await this.app.close();
}
}
private getPropertyNames(instance: any): string[] {
return Object.getOwnPropertyNames(Object.getPrototypeOf(instance)) as any[];
}
}
new SqlGenerator({ targetDir: './src/infra/sql' })