diff --git a/src/index.ts b/src/index.ts index cdc59190..2f241ddc 100644 --- a/src/index.ts +++ b/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); diff --git a/src/infrastructure/Bundler.ts b/src/infrastructure/Bundler.ts deleted file mode 100644 index bc02bcb8..00000000 --- a/src/infrastructure/Bundler.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { BaseService } from '.'; -import { BaseModelContructorOptions } from './BaseService'; - -function Bundler( - services: T, -): new (baseOptions: BaseModelContructorOptions) => { [K in keyof T]: InstanceType } { - 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; diff --git a/src/infrastructure/Utils.ts b/src/infrastructure/Utils.ts new file mode 100644 index 00000000..fb69d3e9 --- /dev/null +++ b/src/infrastructure/Utils.ts @@ -0,0 +1,11 @@ +export function bundler(services: T) { + return (function Bundle(options?: any) { + Object.entries(services || {}).forEach(([name, ser]) => { + this[name] = new ser(options); + }); + } as any) as Bundle; +} + +export function skipAllCaps(key, convert, options) { + return /^[A-Z0-9_]+$/.test(key) ? key : convert(key, options); +}