diff --git a/client/__tests__/util/annoMatrix/serverMocks/routes.ts b/client/__tests__/util/annoMatrix/serverMocks/routes.ts index f195026a..a5b9c34c 100644 --- a/client/__tests__/util/annoMatrix/serverMocks/routes.ts +++ b/client/__tests__/util/annoMatrix/serverMocks/routes.ts @@ -34,7 +34,7 @@ function makeMockColumn(s: any, length: any) { return new Array(length).fill(s.categories[0]); default: - throw new Error("unkonwn type"); + throw new Error("unknown type"); } } diff --git a/client/__tests__/util/annoMatrix/serverMocks/schema.ts b/client/__tests__/util/annoMatrix/serverMocks/schema.ts index f957a352..2bdb63d5 100644 --- a/client/__tests__/util/annoMatrix/serverMocks/schema.ts +++ b/client/__tests__/util/annoMatrix/serverMocks/schema.ts @@ -1,4 +1,4 @@ -import { RawSchema } from "../../../../src/common/types/entities"; +import { RawSchema } from "../../../../src/common/types/schema"; export const schema: { schema: RawSchema } = { schema: { diff --git a/client/__tests__/util/stateManager/sampleResponses.ts b/client/__tests__/util/stateManager/sampleResponses.ts index 77c15689..f5ef9254 100644 --- a/client/__tests__/util/stateManager/sampleResponses.ts +++ b/client/__tests__/util/stateManager/sampleResponses.ts @@ -5,7 +5,7 @@ import zip from "lodash.zip"; import _ from "lodash"; import { flatbuffers } from "flatbuffers"; import { NetEncoding } from "../../../src/util/stateManager/matrix_generated"; -import { RawSchema } from "../../../src/common/types/entities"; +import { RawSchema } from "../../../src/common/types/schema"; /* test data mocking REST 0.2 API responses. Used in several tests. diff --git a/client/src/common/types/entities.ts b/client/src/common/types/entities.ts index c1f2e8e4..fabef218 100644 --- a/client/src/common/types/entities.ts +++ b/client/src/common/types/entities.ts @@ -1,60 +1,3 @@ // If a globally shared type or interface doesn't have a clear owner, put it here -export type Category = number | string | boolean; - -export interface AnnotationColumn { - categories?: Category[]; - name: string; - type: "string" | "float32" | "int32" | "categorical" | "boolean"; - writable: boolean; -} - -interface DataFrame { - nObs: number; - nVar: number; - // TODO(thuang): Not sure what other types are available - type: "float32"; -} - -export interface LayoutColumn { - dims: string[]; - name: string; - // TODO(thuang): Not sure what other types are available - type: "float32"; -} -interface RawLayout { - obs: LayoutColumn[]; - var?: LayoutColumn[]; -} - -interface RawAnnotations { - obs: { - columns: AnnotationColumn[]; - index: string; - }; - var: { - columns: AnnotationColumn[]; - index: string; - }; -} - -export interface RawSchema { - annotations: RawAnnotations; - dataframe: DataFrame; - layout: RawLayout; -} - -interface Annotations extends RawAnnotations { - obsByName: { [name: string]: AnnotationColumn }; - varByName: { [name: string]: AnnotationColumn }; -} - -interface Layout extends RawLayout { - obsByName: { [name: string]: LayoutColumn }; - varByName: { [name: string]: LayoutColumn }; -} - -export interface Schema extends RawSchema { - annotations: Annotations; - layout: Layout; -} +export {}; diff --git a/client/src/common/types/schema.ts b/client/src/common/types/schema.ts new file mode 100644 index 00000000..12dbb34f --- /dev/null +++ b/client/src/common/types/schema.ts @@ -0,0 +1,58 @@ +type Category = number | string | boolean; + +export interface AnnotationColumnSchema { + categories?: Category[]; + name: string; + type: "string" | "float32" | "int32" | "categorical" | "boolean"; + writable: boolean; +} + +interface XMatrixSchema { + nObs: number; + nVar: number; + // TODO(thuang): Not sure what other types are available + type: "float32"; +} + +export interface EmbeddingSchema { + dims: string[]; + name: string; + // TODO(thuang): Not sure what other types are available + type: "float32"; +} +interface RawLayoutSchema { + obs: EmbeddingSchema[]; + var?: EmbeddingSchema[]; +} + +interface RawAnnotationsSchema { + obs: { + columns: AnnotationColumnSchema[]; + index: string; + }; + var: { + columns: AnnotationColumnSchema[]; + index: string; + }; +} + +export interface RawSchema { + annotations: RawAnnotationsSchema; + dataframe: XMatrixSchema; + layout: RawLayoutSchema; +} + +interface AnnotationsSchema extends RawAnnotationsSchema { + obsByName: { [name: string]: AnnotationColumnSchema }; + varByName: { [name: string]: AnnotationColumnSchema }; +} + +interface LayoutSchema extends RawLayoutSchema { + obsByName: { [name: string]: EmbeddingSchema }; + varByName: { [name: string]: EmbeddingSchema }; +} + +export interface Schema extends RawSchema { + annotations: AnnotationsSchema; + layout: LayoutSchema; +} diff --git a/client/src/util/stateManager/annotationsHelpers.ts b/client/src/util/stateManager/annotationsHelpers.ts index 0ff6e9d0..f6b30d8d 100644 --- a/client/src/util/stateManager/annotationsHelpers.ts +++ b/client/src/util/stateManager/annotationsHelpers.ts @@ -3,7 +3,7 @@ Helper functions for user-editable annotations state management. See also reducers/annotations.js */ -import { Schema } from "../../common/types/entities"; +import { Schema } from "../../common/types/schema"; /* There are a number of state constraints assumed throughout the diff --git a/client/src/util/stateManager/schemaHelpers.ts b/client/src/util/stateManager/schemaHelpers.ts index eaf2aeed..84056754 100644 --- a/client/src/util/stateManager/schemaHelpers.ts +++ b/client/src/util/stateManager/schemaHelpers.ts @@ -11,9 +11,9 @@ import catLabelSort from "../catLabelSort"; import { RawSchema, Schema, - LayoutColumn, - AnnotationColumn, -} from "../../common/types/entities"; + EmbeddingSchema, + AnnotationColumnSchema, +} from "../../common/types/schema"; /* System wide schema assumptions: @@ -86,7 +86,7 @@ export function removeObsAnnoColumn(schema: Schema, name: string): Schema { export function addObsAnnoColumn( schema: Schema, _: string, - defn: AnnotationColumn + defn: AnnotationColumnSchema ): Schema { const newSchema = _copyObsAnno(schema); @@ -142,7 +142,7 @@ export function addObsAnnoCategory(schema: any, name: any, category: any) { return newSchema; } -export function addObsLayout(schema: Schema, layout: LayoutColumn): Schema { +export function addObsLayout(schema: Schema, layout: EmbeddingSchema): Schema { /* add or replace a layout */ const newSchema = _copyObsLayout(schema); newSchema.layout.obs.push(layout);