Skip to content

Commit

Permalink
refactor: Improve dimension types
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 1, 2023
1 parent 75b7712 commit 623abbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
24 changes: 12 additions & 12 deletions app/domain/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type DataCubeMetadata = {

export type Component = Dimension | Measure;

type BasicComponent = {
export type BaseComponent = {
cubeIri: string;
iri: string;
label: string;
Expand All @@ -99,7 +99,7 @@ type BasicComponent = {
related?: RelatedDimension[];
};

type BasicDimension = BasicComponent & {
export type BaseDimension = BaseComponent & {
hierarchy?: HierarchyValue[] | null;
} & (
| {
Expand All @@ -124,50 +124,50 @@ export type Dimension =
| GeoShapesDimension
| StandardErrorDimension;

export type NominalDimension = BasicDimension & {
export type NominalDimension = BaseDimension & {
__typename: "NominalDimension";
};

export type OrdinalDimension = BasicDimension & {
export type OrdinalDimension = BaseDimension & {
__typename: "OrdinalDimension";
};

export type TemporalDimension = BasicDimension & {
export type TemporalDimension = BaseDimension & {
__typename: "TemporalDimension";
timeUnit: TimeUnit;
timeFormat: string;
};

export type TemporalOrdinalDimension = BasicDimension & {
export type TemporalOrdinalDimension = BaseDimension & {
__typename: "TemporalOrdinalDimension";
};

export type GeoCoordinatesDimension = BasicDimension & {
export type GeoCoordinatesDimension = BaseDimension & {
__typename: "GeoCoordinatesDimension";
};

export type GeoShapesDimension = BasicDimension & {
export type GeoShapesDimension = BaseDimension & {
__typename: "GeoShapesDimension";
};

export type StandardErrorDimension = BasicDimension & {
export type StandardErrorDimension = BaseDimension & {
__typename: "StandardErrorDimension";
};

export type Measure = NumericalMeasure | OrdinalMeasure;

type BasicMeasure = BasicComponent & {
type BaseMeasure = BaseComponent & {
isCurrency?: boolean;
isDecimal?: boolean;
currencyExponent?: number;
resolution?: number;
};

export type NumericalMeasure = BasicMeasure & {
export type NumericalMeasure = BaseMeasure & {
__typename: "NumericalMeasure";
};

export type OrdinalMeasure = BasicMeasure & {
export type OrdinalMeasure = BaseMeasure & {
__typename: "OrdinalMeasure";
};

Expand Down
8 changes: 5 additions & 3 deletions app/graphql/resolvers/rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { LRUCache } from "typescript-lru-cache";

import { Filters } from "@/configurator";
import {
BaseComponent,
BaseDimension,
Dimension,
DimensionValue,
Measure,
Expand Down Expand Up @@ -189,7 +191,7 @@ export const dataCubeComponents: NonNullable<
b.position ?? b.value ?? undefined
)
);
const baseComponent = {
const baseComponent: BaseComponent = {
// We need to use original iri here, as the cube iri might have changed.
cubeIri: iri,
iri: data.iri,
Expand Down Expand Up @@ -230,7 +232,7 @@ export const dataCubeComponents: NonNullable<
filters ? undefined : values
)
: null;
const baseDimension = {
const baseDimension: BaseDimension = {
...baseComponent,
hierarchy,
};
Expand All @@ -253,7 +255,7 @@ export const dataCubeComponents: NonNullable<
break;
}
default: {
const dimension: Dimension = {
const dimension: Exclude<Dimension, TemporalDimension> = {
__typename: dimensionType,
...baseDimension,
};
Expand Down

0 comments on commit 623abbc

Please sign in to comment.