mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-25 16:04:01 +00:00
refactor: Updating bundler function to follow the function name standard
This commit is contained in:
parent
bbd0b09cd1
commit
3ad35f69fe
12
src/index.ts
12
src/index.ts
@ -1,11 +1,11 @@
|
||||
import { bundler } from './infrastructure';
|
||||
import * as APIServices from './services';
|
||||
import { Bundler } from './infrastructure';
|
||||
|
||||
// All seperatly
|
||||
// All separately
|
||||
export * from './services';
|
||||
|
||||
// Groups
|
||||
export const GroupsBundle = Bundler({
|
||||
export const GroupsBundle = bundler({
|
||||
Groups: APIServices.Groups,
|
||||
GroupAccessRequests: APIServices.GroupAccessRequests,
|
||||
GroupBadges: APIServices.GroupBadges,
|
||||
@ -22,7 +22,7 @@ export const GroupsBundle = Bundler({
|
||||
});
|
||||
|
||||
// Users
|
||||
export const UsersBundle = Bundler({
|
||||
export const UsersBundle = bundler({
|
||||
Users: APIServices.Users,
|
||||
UserCustomAttributes: APIServices.UserCustomAttributes,
|
||||
UserEmails: APIServices.UserEmails,
|
||||
@ -32,7 +32,7 @@ export const UsersBundle = Bundler({
|
||||
});
|
||||
|
||||
// Projects
|
||||
export const ProjectsBundle = Bundler({
|
||||
export const ProjectsBundle = bundler({
|
||||
Branches: APIServices.Branches,
|
||||
Commits: APIServices.Commits,
|
||||
CommitDiscussions: APIServices.CommitDiscussions,
|
||||
@ -77,4 +77,4 @@ export const ProjectsBundle = Bundler({
|
||||
});
|
||||
|
||||
// All initialized
|
||||
export default Bundler(APIServices);
|
||||
export const Gitlab = bundler(APIServices);
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
import { BaseService } from '.';
|
||||
import { BaseModelContructorOptions } from './BaseService';
|
||||
|
||||
function Bundler<T extends { [K: string]: typeof BaseService }>(
|
||||
services: T,
|
||||
): new (baseOptions: BaseModelContructorOptions) => { [K in keyof T]: InstanceType<T[K]> } {
|
||||
const combined = { ...services as object } as T;
|
||||
interface BundleClass {
|
||||
[K: string]: BaseService;
|
||||
}
|
||||
return class Bundle implements BundleClass {
|
||||
[K: string]: any;
|
||||
constructor(baseOptions: BaseModelContructorOptions) {
|
||||
Object.keys(combined).forEach((serviceName) => {
|
||||
this[serviceName] = new combined[serviceName](baseOptions);
|
||||
});
|
||||
}
|
||||
} as temporaryAny;
|
||||
}
|
||||
|
||||
export default Bundler;
|
||||
11
src/infrastructure/Utils.ts
Normal file
11
src/infrastructure/Utils.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export function bundler<T extends { [name: string]: Constructor }, P extends keyof T>(services: T) {
|
||||
return (function Bundle(options?: any) {
|
||||
Object.entries(services || {}).forEach(([name, ser]) => {
|
||||
this[name] = new ser(options);
|
||||
});
|
||||
} as any) as Bundle<T, P>;
|
||||
}
|
||||
|
||||
export function skipAllCaps(key, convert, options) {
|
||||
return /^[A-Z0-9_]+$/.test(key) ? key : convert(key, options);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user