Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
schema change #2
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Apr 28, 2020
1 parent 1517d20 commit 6a96bfc
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface SpaceActionBuilders extends OrchestratedActionBuilders {
) => GetAllOrganizationSpaces;
}

const a = () => { };
a.test = true;


export const spaceActionBuilders: SpaceActionBuilders = {
get: (
guid: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { endpointEntitiesSelector } from '../../../../store/src/selectors/endpoi
import { APIResource, EntityInfo } from '../../../../store/src/types/api.types';
import { PaginatedAction, PaginationEntityState } from '../../../../store/src/types/pagination.types';
import { cfEntityCatalog } from '../../cf-entity-catalog';
import { cfEntityFactory } from '../../cf-entity-factory';
import { CF_ENDPOINT_TYPE, CFEntityConfig } from '../../cf-types';
import { createEntityRelationKey } from '../../entity-relations/entity-relations.types';
import { AppStat } from '../../store/types/app-metadata.types';
Expand Down Expand Up @@ -92,6 +93,7 @@ export class ApplicationService {
private paginationMonitorFactory: PaginationMonitorFactory,
) {
this.appEntityService = cfEntityCatalog.application.store.getEntityService(
undefined,
appGuid,
cfGuid,
{
Expand All @@ -100,6 +102,7 @@ export class ApplicationService {
}
);
this.appSummaryEntityService = cfEntityCatalog.appSummary.store.getEntityService(
undefined,
appGuid,
cfGuid
);
Expand Down Expand Up @@ -171,7 +174,10 @@ export class ApplicationService {
first(),
switchMap(app => {
return cfEntityCatalog.space.store.getEntityService({
schemaKey: spaceWithOrgEntityType
schema: {
entity: [cfEntityFactory(spaceWithOrgEntityType)],
schemaKey: spaceWithOrgEntityType
}
},
app.space_guid,
app.cfGuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class AddEditSpaceStepBase {
this.cfGuid = activeRouteCfOrgSpace.cfGuid;
this.orgGuid = activeRouteCfOrgSpace.orgGuid;
this.allSpacesInOrg$ = cfEntityCatalog.space.store.getAllInOrganization.getPaginationService(
undefined,
this.orgGuid,
this.cfGuid,
getPaginationKey(organizationEntityType, this.orgGuid), {
Expand All @@ -45,31 +46,10 @@ export class AddEditSpaceStepBase {
tap(spaceNames => this.allSpacesInOrg = spaceNames),
first(),
);
// const paginationKey = getPaginationKey(organizationEntityType, this.orgGuid);
// const spaceEntity = entityCatalog.getEntity(CF_ENDPOINT_TYPE, spaceEntityType);
// const getAllSpaceActionBuilder = spaceEntity.actionOrchestrator.getActionBuilder('getAllInOrganization');
// const action = getAllSpaceActionBuilder(this.orgGuid, this.cfGuid, paginationKey) as PaginatedAction;
// this.allSpacesInOrg$ = getPaginationObservables<APIResource, CFAppState>(
// {
// store: this.store,
// action,
// paginationMonitor: this.paginationMonitorFactory.create(
// action.paginationKey,
// new CFEntityConfig(spaceEntityType),
// action.flattenPagination
// )
// },
// action.flattenPagination
// ).entities$.pipe(
// filter(spaces => !!spaces),
// map(spaces => spaces.map(space => space.entity.name)),
// tap(spaceNames => this.allSpacesInOrg = spaceNames),
// first(),
// );
this.fetchSpacesSubscription = this.allSpacesInOrg$.subscribe();


this.quotaDefinitions$ = cfEntityCatalog.spaceQuota.store.getAllInOrganization.getPaginationService(
undefined,
this.orgGuid,
this.cfGuid,
createEntityRelationPaginationKey(organizationEntityType, this.orgGuid)
Expand All @@ -78,30 +58,6 @@ export class AddEditSpaceStepBase {
first()
);

// const quotaPaginationKey = createEntityRelationPaginationKey(organizationEntityType, this.orgGuid);

// const spaceQuotaEntity = entityCatalog.getEntity<IEntityMetadata, any, SpaceQuotaDefinitionActionBuilders>(
// CF_ENDPOINT_TYPE,
// spaceQuotaEntityType
// );
// const actionBuilder = spaceQuotaEntity.actionOrchestrator.getActionBuilder('getAllInOrganization');
// const getAllInOrganization = actionBuilder(this.orgGuid, this.cfGuid, quotaPaginationKey);
// this.quotaDefinitions$ = getPaginationObservables<APIResource<ISpaceQuotaDefinition>>(
// {
// store: this.store,
// action: getAllInOrganization as PaginatedAction,
// paginationMonitor: this.paginationMonitorFactory.create(
// quotaPaginationKey,
// cfEntityFactory(spaceQuotaEntityType),
// getAllInOrganization.flattenPagination
// )
// },
// getAllInOrganization.flattenPagination
// ).entities$.pipe(
// filter(o => !!o),
// first()
// );

this.hasSpaceQuotas$ = this.quotaDefinitions$.pipe(
map(q => q && q.length > 0)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class CloudFoundryUserProvidedServicesService {
).entity$.subscribe(a => console.log('entMonitor: ', a));

const entService = cfEntityCatalog.userProvidedService.store.getEntityService(
undefined,
upsiGuid, // Per action builder
endpointGuid, {
includeRelations: [
Expand All @@ -76,11 +77,13 @@ export class CloudFoundryUserProvidedServicesService {
).entityObs$.subscribe(a => console.log('entService: ', a));

const pagMon = cfEntityCatalog.userProvidedService.store.getPaginationMonitor(
undefined,
pagKey, // Per action builder
endpointGuid, // Per action builder
).currentPage$.subscribe(a => console.log('pagMon: ', a));

const pagObservables = cfEntityCatalog.userProvidedService.store.getPaginationService(
undefined,
pagKey, // Per action builder
endpointGuid, // Per action builder
).entities$.subscribe(a => console.log('pagObservables: ', a));
Expand All @@ -102,6 +105,7 @@ export class CloudFoundryUserProvidedServicesService {

// cfEntityCatalog.userProvidedServiceEntity.storage2.instances.
const allInSpacePagMonitor = cfEntityCatalog.userProvidedService.store.getAllInSpace.getPaginationMonitor(
undefined,
endpointGuid, // Per action builder
spaceGuid, // Per action builder
null, // Per action builder
Expand All @@ -110,6 +114,7 @@ export class CloudFoundryUserProvidedServicesService {
).currentPage$.subscribe(a => console.log('allInSpacePagMonitor: ', a));

const allInSpacePagObservables = cfEntityCatalog.userProvidedService.store.getAllInSpace.getPaginationService(
undefined,
endpointGuid, // Per action builder
spaceGuid, // Per action builder
null, // Per action builder
Expand All @@ -125,13 +130,14 @@ export class CloudFoundryUserProvidedServicesService {
{} as Partial<IUserProvidedServiceInstanceData> // Per action builder
);
// this.store.dispatch(updateAction);

}

public getUserProvidedServices(cfGuid: string, spaceGuid?: string, relations = getUserProvidedServiceInstanceRelations)
: Observable<APIResource<IUserProvidedServiceInstance>[]> {

const pagObs = cfEntityCatalog.userProvidedService.store.getAllInSpace.getPaginationService(
cfGuid, spaceGuid, null, relations, true
undefined, cfGuid, spaceGuid, null, relations, true
);
return combineLatest([
pagObs.entities$, // Ensure entities is subbed to the fetch kicks off
Expand Down Expand Up @@ -163,7 +169,7 @@ export class CloudFoundryUserProvidedServicesService {
}

public getUserProvidedService(cfGuid: string, upsGuid: string): Observable<APIResource<IUserProvidedServiceInstance>> {
return cfEntityCatalog.userProvidedService.store.getEntityService(upsGuid, cfGuid, {}).waitForEntity$.pipe(
return cfEntityCatalog.userProvidedService.store.getEntityService(undefined, upsGuid, cfGuid, {}).waitForEntity$.pipe(
map(e => e.entity)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export type OrchestratedActionBuilder<
export type KnownEntityActionBuilder<
T extends Record<any, any> = Record<any, any>
> = (guid: string, endpointGuid: string, extraArgs?: T) => EntityRequestAction;
// TODO: RC ADD SCHEMA KEY TO THIS AND GetMultipleActionBuilder? option 1
// TODO: RC add schemeKey option to getEntityService. pagination types can return their own action
// TODO: RC add a getSpaceWithOrg.getEntityService concept
// createTrackingId should be unique to the thing that's being created.
// It is used to track the status of the entity creation.
export type CreateActionBuilder<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
PaginationRequestActionConfig,
} from '../action-orchestrator/action-orchestrator';

export interface EntityCatalogStoreParams {
schemaKey: string;
}

export class ActionBuilderConfigMapper {

static actionKeyHttpMethodMapper = {
Expand Down Expand Up @@ -49,10 +53,14 @@ export class ActionBuilderConfigMapper {
schemaGetter: (schemaKey: string) => EntitySchema
): OrchestratedActionBuilder {
if (configOrBuilder instanceof EntityRequestActionConfig) {
return (...args: Parameters<KnownEntityActionBuilder>) => {
return (
params?: EntityCatalogStoreParams, // TODO: RC RENAME
...args: Parameters<KnownEntityActionBuilder>
) => {
const [guid, endpointGuid, ...meta] = args;
const schemaKey = params && params.schemaKey ? params.schemaKey : configOrBuilder.schemaKey
return new BaseEntityRequestAction(
schemaGetter(configOrBuilder.schemaKey),
schemaGetter(schemaKey),
guid,
endpointGuid,
entityType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { PaginationMonitor } from '../../monitors/pagination-monitor';
import { ListActionState, RequestInfoState } from '../../reducers/api-request-reducer/types';
import { PaginationObservables } from '../../reducers/pagination-reducer/pagination-reducer.types';
import { isPaginatedAction, PaginatedAction } from '../../types/pagination.types';
import { RequestAction } from '../../types/request.types';
import { EntityRequestAction, RequestAction } from '../../types/request.types';
import {
ActionOrchestrator,
OrchestratedActionBuilder,
OrchestratedActionBuilders,
} from '../action-orchestrator/action-orchestrator';
import { EntityCatalogHelpers } from '../entity-catalog.helper';
import { KnownActionBuilders } from './entity-catalog-entity';
import {
CoreEntityCatalogEntityStore,
EntityCatalogEntityStore,
Expand All @@ -30,6 +31,14 @@ export type ActionDispatchers<ABC extends OrchestratedActionBuilders> = {
[K in keyof ABC]: ActionDispatcher<K, ABC>
};

// const applySchema = <T extends EntityRequestAction>(action: T, params: EntityCatalogStoreParams): T => {
// if (params && params.schema) {
// action.entity = params.schema.entity || action.entity;
// action.schemaKey = params.schema.schemaKey || action.schemaKey;
// }
// return action;
// }

export class EntityCatalogEntityStoreHelpers {
private static createPaginationMonitor<Y>(
actionBuilderKey: string,
Expand Down Expand Up @@ -136,7 +145,7 @@ export class EntityCatalogEntityStoreHelpers {
if (!actionBuilder) {
throw new Error(`\`get\` action builder not implemented for ${entityKey}`);
}
const action = actionBuilder(...args);
const action = applySchema<ReturnType<ABC["get"]>>(actionBuilder(...args), params);
return helper.esf.create<Y>(
action.guid,
action
Expand All @@ -152,7 +161,7 @@ export class EntityCatalogEntityStoreHelpers {
}
return EntityCatalogEntityStoreHelpers.createPaginationMonitor(
'getMultiple',
actionBuilder(...args),
applySchema<ReturnType<ABC["getMultiple"]>>(actionBuilder(...args), params),
);
},
getPaginationService: (
Expand All @@ -165,14 +174,14 @@ export class EntityCatalogEntityStoreHelpers {
}
return EntityCatalogEntityStoreHelpers.createPaginationService(
'getMultiple',
actionBuilder(...args),
applySchema<ReturnType<ABC["getMultiple"]>>(actionBuilder(...args), params),
);
},
};
}

static getPaginationStore<Y, ABC extends OrchestratedActionBuilders = OrchestratedActionBuilders, K extends keyof ABC = ''>(
builders: ABC,
builders: KnownActionBuilders<ABC>,
): PaginationEntityCatalogEntityStore<Y, PaginatedActionBuilders<ABC>> {
if (!builders) {
return {} as PaginationEntityCatalogEntityStore<Y, PaginatedActionBuilders<ABC>>;
Expand All @@ -184,19 +193,21 @@ export class EntityCatalogEntityStoreHelpers {
...entityInstances,
[key]: {
getPaginationMonitor: (
...args: Parameters<ABC[K]>
params?: EntityCatalogStoreParams,
...args: any
): PaginationMonitor<Y> => {
return EntityCatalogEntityStoreHelpers.createPaginationMonitor(
key,
builders[key](...args)
applySchema<EntityRequestAction>(builders[key](...args), params),
);
},
getPaginationService: (
params?: EntityCatalogStoreParams,
...args: Parameters<ABC[K]>
): PaginationObservables<Y> => {
return EntityCatalogEntityStoreHelpers.createPaginationService(
key,
builders[key](...args)
applySchema<EntityRequestAction>(builders[key](...args), params),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ActionBuilderConfigMapper } from './action-builder-config.mapper';
import { EntityCatalogEntityStore } from './entity-catalog-entity.types';
import { ActionDispatchers, EntityCatalogEntityStoreHelpers } from './entity-catalog-TOSORT';

type KnownActionBuilders<ABC extends OrchestratedActionBuilders> = Pick<ABC, NonOptionalKeys<Pick<ABC, KnownKeys<ABC>>>>
export type KnownActionBuilders<ABC extends OrchestratedActionBuilders> = Pick<ABC, NonOptionalKeys<Pick<ABC, KnownKeys<ABC>>>>

export interface EntityCatalogBuilders<
T extends IEntityMetadata = IEntityMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { PaginationObservables } from '../../reducers/pagination-reducer/paginat
import { PaginatedAction } from '../../types/pagination.types';
import { OrchestratedActionBuilders, OrchestratedActionCoreBuilders } from '../action-orchestrator/action-orchestrator';

export interface EntityCatalogStoreParams {
schemaKey?: string;
}

// TODO: RC tidy up `extends OrchestratedActionBuilders`, could be more specific
/**
* Core entity and entities access (entity/entities monitors and services)
Expand Down Expand Up @@ -69,9 +65,11 @@ export type PaginatedActionBuilders<ABC extends OrchestratedActionBuilders> = Om
export type PaginationEntityCatalogEntityStore<Y, ABC extends OrchestratedActionBuilders> = {
[K in keyof ABC]: {
getPaginationMonitor: (
params?: EntityCatalogStoreParams,
...args: Parameters<ABC[K]>
) => PaginationMonitor<Y>;
getPaginationService: (
params?: EntityCatalogStoreParams,
...args: Parameters<ABC[K]>
) => PaginationObservables<Y>;
}
Expand Down

0 comments on commit 6a96bfc

Please sign in to comment.