Skip to content

Commit

Permalink
feat: Rename classes to be more consistent between use of 'Bravo' vs.…
Browse files Browse the repository at this point in the history
… 'Favro'
  • Loading branch information
adam-coster committed Jul 1, 2021
1 parent ae464db commit 6d34319
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 54 deletions.
40 changes: 20 additions & 20 deletions src/lib/BravoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
findRequiredByField,
stringsMatchIgnoringCase,
} from './utility.js';
import { FavroCollection } from './FavroCollection';
import { FavroUser } from './FavroUser';
import { FavroOrganization } from './FavroOrganization';
import { FavroWidget } from './FavroWidget.js';
import { BravoCollection } from './BravoCollection';
import { BravoUser } from './users';
import { BravoOrganization } from './BravoOrganization';
import { BravoWidget } from './BravoWidget.js';
import type { DataFavroWidget } from '$/types/FavroWidgetTypes.js';
import type {
OptionFavroCollectionVisibility,
Expand Down Expand Up @@ -54,10 +54,10 @@ export class BravoClient extends FavroClient {
{
excludeOrganizationId: true,
},
FavroOrganization,
BravoOrganization,
);
this.cache.organizations =
(await res.getAllEntities()) as FavroOrganization[];
(await res.getAllEntities()) as BravoOrganization[];
}
return this.cache.organizations;
}
Expand Down Expand Up @@ -101,9 +101,9 @@ export class BravoClient extends FavroClient {
const res = await this.requestWithReturnedEntities(
'users',
{ method: 'get' },
FavroUser,
BravoUser,
);
this.cache.users = (await res.getAllEntities()) as FavroUser[];
this.cache.users = (await res.getAllEntities()) as BravoUser[];
}
return this.cache.users;
}
Expand Down Expand Up @@ -180,10 +180,10 @@ export class BravoClient extends FavroClient {
// ],
},
},
FavroCollection,
BravoCollection,
);
const collection = (await res.getAllEntities())[0] as
| FavroCollection
| BravoCollection
| undefined;
assertBravoClaim(collection, `Failed to create collection`);
this.cache.addCollection(collection);
Expand Down Expand Up @@ -227,10 +227,10 @@ export class BravoClient extends FavroClient {
const res = await this.requestWithReturnedEntities(
'collections',
{ method: 'get' },
FavroCollection,
BravoCollection,
);
this.cache.collections =
(await res.getAllEntities()) as FavroCollection[];
(await res.getAllEntities()) as BravoCollection[];
}
return this.cache.collections;
}
Expand Down Expand Up @@ -266,14 +266,14 @@ export class BravoClient extends FavroClient {
const res = await this.requestWithReturnedEntities(
`collections/${collectionId}`,
{ method: 'get' },
FavroCollection,
BravoCollection,
);
const collections = await res.getAllEntities();
assertBravoClaim(
collections.length == 1,
`No collection found with id ${collectionId}`,
);
collection = collections[0] as FavroCollection;
collection = collections[0] as BravoCollection;
}
return collection;
}
Expand All @@ -293,8 +293,8 @@ export class BravoClient extends FavroClient {
const res = (await this.requestWithReturnedEntities(
'widgets',
{ method: 'get', query: { collectionId } },
FavroWidget,
)) as BravoResponseEntities<DataFavroWidget, FavroWidget>;
BravoWidget,
)) as BravoResponseEntities<DataFavroWidget, BravoWidget>;
this.cache.addWidgets(res, collectionId);
}
return this.cache.getWidgets(collectionId)!;
Expand All @@ -307,18 +307,18 @@ export class BravoClient extends FavroClient {
*/
async listWidgets(collectionId?: string) {
const pager = await this.getWidgetsAsyncGenerator(collectionId);
const widgets = ((await pager?.getAllEntities()) || []) as FavroWidget[];
const widgets = ((await pager?.getAllEntities()) || []) as BravoWidget[];
return widgets;
}

async findWidgetById(widgetCommonId: string) {
const res = await this.requestWithReturnedEntities(
`widgets/${widgetCommonId}`,
{ method: 'get' },
FavroWidget,
BravoWidget,
);
const [widget] = await res.getAllEntities();
return widget as FavroWidget;
return widget as BravoWidget;
}

/**
Expand All @@ -327,7 +327,7 @@ export class BravoClient extends FavroClient {
* by the search are cached.
*/
async findWidget(
matchFunction: (widget: FavroWidget, idx?: number) => any,
matchFunction: (widget: BravoWidget, idx?: number) => any,
collectionId = '',
) {
// Reduce API calls by non-exhaustively searching (when possible)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/FavroCollection.ts → src/lib/BravoCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataFavroCollection } from '../types/FavroApiTypes';
import { FavroEntity } from './FavroEntity.js';
import { BravoEntity } from './BravoEntity.js';

export class FavroCollection extends FavroEntity<DataFavroCollection> {
export class BravoCollection extends BravoEntity<DataFavroCollection> {
get name() {
return this._data.name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/FavroEntity.ts → src/lib/BravoEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BravoClient } from './BravoClient.js';
/**
* Base class for Favro Entities (wrapping raw API data)
*/
export class FavroEntity<EntityData> {
export class BravoEntity<EntityData> {
constructor(protected _client: BravoClient, protected _data: EntityData) {}

toJSON() {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/FavroOrganization.ts → src/lib/BravoOrganization.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { DataFavroOrganization } from '../types/FavroApiTypes';
import { FavroEntity } from './FavroEntity.js';
import { FavroOrganizationMember } from './FavroUser.js';
import { BravoEntity } from './BravoEntity.js';
import { BravoOrganizationMember } from './users.js';

export class FavroOrganization extends FavroEntity<DataFavroOrganization> {
export class BravoOrganization extends BravoEntity<DataFavroOrganization> {
get name() {
return this._data.name;
}

get sharedToUsers() {
return this._data.sharedToUsers.map(
(u) => new FavroOrganizationMember(this._client, u),
(u) => new BravoOrganizationMember(this._client, u),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/FavroWidget.ts → src/lib/BravoWidget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataFavroWidget } from '$/types/FavroWidgetTypes.js';
import { FavroEntity } from './FavroEntity';
import { BravoEntity } from './BravoEntity';

export class FavroWidget extends FavroEntity<DataFavroWidget> {
export class BravoWidget extends BravoEntity<DataFavroWidget> {
get widgetCommonId() {
return this._data.widgetCommonId;
}
Expand Down
20 changes: 10 additions & 10 deletions src/lib/clientLib/BravoClientCache.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FavroOrganization } from '@/FavroOrganization.js';
import { FavroUser } from '@/FavroUser.js';
import { FavroCollection } from '@/FavroCollection.js';
import { BravoOrganization } from '@/BravoOrganization.js';
import { BravoUser } from '@/users.js';
import { BravoCollection } from '@/BravoCollection.js';
import type { BravoResponseWidgets } from './BravoResponse.js';
import { assertBravoClaim } from '@/errors.js';

export class BravoClientCache {
protected _organizations?: FavroOrganization[];
protected _users?: FavroUser[];
protected _collections?: FavroCollection[];
protected _organizations?: BravoOrganization[];
protected _users?: BravoUser[];
protected _collections?: BravoCollection[];
/**
* Widget paging results keyed by collectionId, with the empty string `''`
* used to key the paging result from not using a collectionId (global).
Expand All @@ -18,23 +18,23 @@ export class BravoClientCache {
// @ts-expect-error
return this._collections ? [...this._collections] : undefined;
}
set collections(collections: FavroCollection[]) {
set collections(collections: BravoCollection[]) {
this._collections = collections;
}

get users() {
// @ts-expect-error
return this._users ? [...this._users] : undefined;
}
set users(users: FavroUser[]) {
set users(users: BravoUser[]) {
this._users = users;
}

get organizations() {
// @ts-expect-error
return this._organizations ? [...this._organizations] : undefined;
}
set organizations(orgs: FavroOrganization[]) {
set organizations(orgs: BravoOrganization[]) {
this._organizations = orgs;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ export class BravoClientCache {
* will be replaced by the one provided in this call (e.g. for
* replacing the cached copy with an updated one).
*/
addCollection(collection: FavroCollection) {
addCollection(collection: BravoCollection) {
if (!this._collections) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/clientLib/BravoResponse.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { DataFavroWidget } from '$/types/FavroWidgetTypes.js';
import type { FavroWidget } from '@/FavroWidget.js';
import type { BravoWidget } from '@/BravoWidget.js';
import { BravoClient } from '@/BravoClient';
import { FavroEntity } from '@/FavroEntity';
import { BravoEntity } from '@/BravoEntity';
import { FavroResponse } from './FavroResponse';

export type BravoResponseWidgets = BravoResponseEntities<
DataFavroWidget,
FavroWidget
BravoWidget
>;

/**
Expand All @@ -15,7 +15,7 @@ export type BravoResponseWidgets = BravoResponseEntities<
*/
export class BravoResponseEntities<
EntityData,
Entity extends FavroEntity<EntityData>,
Entity extends BravoEntity<EntityData>,
> {
private _entitiesCache: Entity[] = [];
private _hydratedLatestPage = false;
Expand Down
1 change: 0 additions & 1 deletion src/lib/clientLib/FavroClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fetch from 'node-fetch';
import { URL } from 'url';
import type {
DataAnyEntity,
ConstructorFavroEntity,
OptionFavroHttpMethod,
} from '$/types/FavroApiTypes';
import { FavroResponse } from '@/clientLib/FavroResponse';
Expand Down
12 changes: 6 additions & 6 deletions src/lib/FavroUser.ts → src/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import type {
DataFavroOrganizationMember,
DataFavroUser,
} from '../types/FavroApiTypes';
import { FavroEntity } from './FavroEntity.js';
import { BravoEntity } from './BravoEntity.js';

export class FavroUserBase<
export class BravoUserBase<
UserData extends { userId: string },
> extends FavroEntity<UserData> {
> extends BravoEntity<UserData> {
get userId() {
return this._data.userId;
}
}

export class FavroUser extends FavroUserBase<DataFavroUser> {
export class BravoUser extends BravoUserBase<DataFavroUser> {
get name() {
return this._data.name;
}
Expand All @@ -28,14 +28,14 @@ export class FavroUser extends FavroUserBase<DataFavroUser> {
}
}

export class FavroOrganizationMember extends FavroUserBase<DataFavroOrganizationMember> {
export class BravoOrganizationMember extends BravoUserBase<DataFavroOrganizationMember> {
/** Role in the organization */
get role() {
return this._data.role;
}
}

export class FavroCollectionMember extends FavroUserBase<DataFavroCollectionMember> {
export class BravoCollectionMember extends BravoUserBase<DataFavroCollectionMember> {
/** Role in the collection */
get role() {
return this._data.role;
Expand Down
4 changes: 2 additions & 2 deletions src/test/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BravoClient } from '@/BravoClient.js';
import { expect } from 'chai';
import fs from 'fs-extra';
import dotenv from 'dotenv';
import { FavroCollection } from '@/FavroCollection.js';
import { BravoCollection } from '@/BravoCollection.js';

/**
* @note A root .env file must be populated with the required
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('BravoClient', function () {
describe('Collections', function () {
this.bail(true);

let testCollection: FavroCollection;
let testCollection: BravoCollection;

it('can list all collections', async function () {
const collections = await client.listCollections();
Expand Down
4 changes: 2 additions & 2 deletions src/types/FavroApiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BravoClient } from '@/BravoClient.js';
import type { FavroEntity } from '@/FavroEntity.js';
import type { BravoEntity } from '@/BravoEntity.js';

export type OptionFavroHttpMethod = 'get' | 'post' | 'put' | 'delete';
export type OptionFavroCollectionColorBackground =
Expand Down Expand Up @@ -87,4 +87,4 @@ export type DataFavroResponse<DataEntity extends DataAnyEntity> =
export type ConstructorFavroEntity<EntityData> = new (
client: BravoClient,
data: EntityData,
) => FavroEntity<EntityData>;
) => BravoEntity<EntityData>;

0 comments on commit 6d34319

Please sign in to comment.