Skip to content

Commit

Permalink
style: rename SHOGunClient to SHOGunAPIClient and cache services afte…
Browse files Browse the repository at this point in the history
…r first creation

BREAKING CHANGE: Renames the SHOGunClient to SHOGunAPIClient
  • Loading branch information
dnlkoch committed Jun 24, 2022
1 parent 0629d8d commit 6fb1b0b
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 149 deletions.
6 changes: 3 additions & 3 deletions src/parser/ShogunApplicationUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import { MapUtil } from '@terrestris/ol-util/dist/MapUtil/MapUtil';
import Application, { DefaultLayerTree } from '../model/Application';
import Layer from '../model/Layer';

import SHOGunClient from '../service/SHOGunClient';
import SHOGunAPIClient from '../service/SHOGunAPIClient';

import { getBearerTokenHeader } from '../security/getBearerTokenHeader';

export interface ShogunApplicationUtilOpts {
client?: SHOGunClient;
client?: SHOGunAPIClient;
}

class ShogunApplicationUtil<T extends Application, S extends Layer> {

private client: SHOGunClient | undefined;
private client: SHOGunAPIClient | undefined;

constructor(opts?: ShogunApplicationUtilOpts) {
// TODO Default client?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import GroupService from './GroupService';

import fetchSpy, { successResponse } from '../spec/fetchSpy';

import SHOGunClient from './SHOGunClient';
import SHOGunAPIClient from './SHOGunAPIClient';
import CacheService from './CacheService';
import FileService from './FileService';
import ImageFileService from './ImageFileService';
Expand All @@ -37,12 +37,12 @@ export default class MyApplication extends Application {
}
}

describe('SHOGunClient', () => {
describe('SHOGunAPIClient', () => {
let fetchMock: jest.SpyInstance;
let client: SHOGunClient;
let client: SHOGunAPIClient;

beforeEach(() => {
client = new SHOGunClient();
client = new SHOGunAPIClient();
});

afterEach(() => {
Expand All @@ -53,7 +53,7 @@ describe('SHOGunClient', () => {
});

it('is defined', () => {
expect(SHOGunClient).toBeDefined();
expect(SHOGunAPIClient).toBeDefined();
});

it('can be instantiated', async () => {
Expand Down
197 changes: 197 additions & 0 deletions src/service/SHOGunAPIClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import Keycloak from 'keycloak-js';

import Application from '../model/Application';
import File from '../model/File';
import Group, { ProviderGroupDetails } from '../model/Group';
import ImageFile from '../model/ImageFile';
import Layer from '../model/Layer';
import User, { ProviderUserDetails } from '../model/User';

import AppInfoService from './AppInfoService';
import ApplicationService from './ApplicationService';
import AuthService from './AuthService';
import CacheService from './CacheService';
import FileService from './FileService';
import GraphQLService from './GraphQLService';
import GroupService from './GroupService';
import ImageFileService from './ImageFileService';
import LayerService from './LayerService';
import OpenAPIService from './OpenAPIService';
import UserService from './UserService';

export interface SHOGunAPIClientOpts {
/**
* The URL to the SHOGun instance, e.g. '/api'. The default is to '/'.
*/
url: string;

/**
* The keycloak instance.
*/
keycloak?: Keycloak;
}

export class SHOGunAPIClient {

private basePath: string;

private keycloak?: Keycloak;

private cacheService?: CacheService;
private appInfoService?: AppInfoService;
private applicationService?: ApplicationService<any>;
private layerService?: LayerService<any>;
private groupService?: GroupService<any>;
private userService?: UserService<any>;
private fileService?: FileService<any>;
private imageFileService?: ImageFileService<any>;
private authService?: AuthService;
private graphqlService?: GraphQLService;
private openapiService?: OpenAPIService;

constructor(opts: SHOGunAPIClientOpts = {
url: '/'
}) {
this.basePath = opts.url;
this.keycloak = opts.keycloak;
}

cache(): CacheService {
if (!this.cacheService) {
this.cacheService = new CacheService({
basePath: `${this.basePath}cache`,
keycloak: this.keycloak
});
}

return this.cacheService;
}

info(): AppInfoService {
if (!this.appInfoService) {
this.appInfoService = new AppInfoService({
basePath: `${this.basePath}info`,
keycloak: this.keycloak
});
}

return this.appInfoService;
}

application<T extends Application>(): ApplicationService<T> {
if (!this.applicationService) {
this.applicationService = new ApplicationService<T>({
basePath: `${this.basePath}applications`,
keycloak: this.keycloak
});
}

return this.applicationService;
}

layer<T extends Layer>(): LayerService<T> {
if (!this.layerService) {
this.layerService = new LayerService<T>({
basePath: `${this.basePath}layers`,
keycloak: this.keycloak
});
}

return this.layerService;
}

group<T extends Group<S>, S extends ProviderGroupDetails>(): GroupService<T, S> {
if (!this.groupService) {
this.groupService = new GroupService<T, S>({
basePath: `${this.basePath}groups`,
keycloak: this.keycloak
});
}

return this.groupService;
}

user<T extends User<S>, S extends ProviderUserDetails>(): UserService<T, S> {
if (!this.userService) {
this.userService = new UserService<T, S>({
basePath: `${this.basePath}users`,
keycloak: this.keycloak
});
}

return this.userService;
}

file<T extends File>(): FileService<T> {
if (!this.fileService) {
this.fileService = new FileService<T>({
basePath: `${this.basePath}files`,
keycloak: this.keycloak
});
}

return this.fileService;
}

imagefile<T extends ImageFile>(): ImageFileService<T> {
if (!this.imageFileService) {
this.imageFileService = new ImageFileService<T>({
basePath: `${this.basePath}imagefiles`,
keycloak: this.keycloak
});
}

return this.imageFileService;
}

auth(): AuthService {
if (!this.authService) {
this.authService = new AuthService({
basePath: `${this.basePath}sso`,
keycloak: this.keycloak
});
}

return this.authService;
}

graphql(): GraphQLService {
if (!this.graphqlService) {
this.graphqlService = new GraphQLService({
basePath: `${this.basePath}graphql`,
keycloak: this.keycloak
});
}

return this.graphqlService;
}

openapi(): OpenAPIService {
if (!this.openapiService) {
this.openapiService = new OpenAPIService({
basePath: `${this.basePath}v2`,
keycloak: this.keycloak
});
}

return this.openapiService;
}

getBasePath() {
return this.basePath;
}

setBasePath(basePath: string) {
this.basePath = basePath;
}

getKeycloak() {
return this.keycloak;
}

setKeycloak(keycloak: Keycloak) {
this.keycloak = keycloak;
}
}

export default SHOGunAPIClient;
141 changes: 0 additions & 141 deletions src/service/SHOGunClient.ts

This file was deleted.

0 comments on commit 6fb1b0b

Please sign in to comment.