From 2d6c4538a2e785e9194601980dcb9944465a38a6 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Tue, 7 Nov 2017 21:40:34 +0100
Subject: [PATCH] renamed Column.Schema.valueKind to valueType

---
 src/apps/domain-annotation-server/utils.ts    |  2 +-
 src/mol-data/db/column.ts                     | 29 ++++++++++---------
 src/mol-io/reader/cif/schema.ts               | 12 ++++----
 src/mol-io/reader/common/text/column/fixed.ts |  6 ++--
 src/mol-io/reader/common/text/column/token.ts |  6 ++--
 src/mol-model/structure/export/mmcif.ts       |  2 +-
 6 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/src/apps/domain-annotation-server/utils.ts b/src/apps/domain-annotation-server/utils.ts
index df4a64171..de3e40b92 100644
--- a/src/apps/domain-annotation-server/utils.ts
+++ b/src/apps/domain-annotation-server/utils.ts
@@ -20,7 +20,7 @@ function ofSchema(schema: Table.Schema) {
     const fields: Encoder.FieldDefinition[] = [];
     for (const k of Object.keys(schema)) {
         const t = schema[k];
-        const type: any = t.valueKind === 'str' ? Encoder.FieldType.Str : t.valueKind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
+        const type: any = t.valueType === 'str' ? Encoder.FieldType.Str : t.valueType === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
         fields.push({ name: k, type, value: columnValue(k), valueKind: columnValueKind(k) })
     }
     return fields;
diff --git a/src/mol-data/db/column.ts b/src/mol-data/db/column.ts
index 76a893cb9..b65e45d0c 100644
--- a/src/mol-data/db/column.ts
+++ b/src/mol-data/db/column.ts
@@ -25,20 +25,21 @@ namespace Column {
     export type Schema<T = any> = Schema.Str | Schema.Int | Schema.Float | Schema.Coordinate | Schema.Aliased<T> | Schema.Tensor
 
     export namespace Schema {
-        export type Str = { '@type': 'str', T: string, valueKind: 'str' }
-        export type Int = { '@type': 'int', T: number, valueKind: 'int' }
-        export type Float = { '@type': 'float', T: number, valueKind: 'float' }
-        export type Coordinate = { '@type': 'coord', T: number, valueKind: 'float' }
+        type Base<T extends string> = { valueType: T }
+        export type Str = { '@type': 'str', T: string } & Base<'str'>
+        export type Int = { '@type': 'int', T: number } & Base<'int'>
+        export type Float = { '@type': 'float', T: number } & Base<'float'>
+        export type Coordinate = { '@type': 'coord', T: number } & Base<'float'>
 
-        export type Tensor = { '@type': 'tensor', T: Tensors, space: Tensors.Space, valueKind: 'tensor' };
-        export type Aliased<T> = { '@type': 'aliased', T: T, valueKind: 'str' | 'int' }
+        export type Tensor = { '@type': 'tensor', T: Tensors, space: Tensors.Space } & Base<'tensor'>
+        export type Aliased<T> = { '@type': 'aliased', T: T } & Base<'str' | 'int'>
 
-        export const str: Str = { '@type': 'str', T: '', valueKind: 'str' };
-        export const int: Int = { '@type': 'int', T: 0, valueKind: 'int' };
-        export const coord: Coordinate = { '@type': 'coord', T: 0, valueKind: 'float' };
-        export const float: Float = { '@type': 'float', T: 0, valueKind: 'float' };
+        export const str: Str = { '@type': 'str', T: '', valueType: 'str' };
+        export const int: Int = { '@type': 'int', T: 0, valueType: 'int' };
+        export const coord: Coordinate = { '@type': 'coord', T: 0, valueType: 'float' };
+        export const float: Float = { '@type': 'float', T: 0, valueType: 'float' };
 
-        export function tensor(space: Tensors.Space): Tensor { return { '@type': 'tensor', T: space.create(), space, valueKind: 'tensor' }; }
+        export function tensor(space: Tensors.Space): Tensor { return { '@type': 'tensor', T: space.create(), space, valueType: 'tensor' }; }
         export function vector(dim: number): Tensor { return tensor(Tensors.Vector(dim)); }
         export function matrix(rows: number, cols: number): Tensor { return tensor(Tensors.ColumnMajorMatrix(rows, cols)); }
 
@@ -182,7 +183,7 @@ function lambdaColumn<T extends Column.Schema>({ value, valueKind, rowCount, sch
 
 function arrayColumn<T extends Column.Schema>({ array, schema, valueKind }: Column.ArraySpec<T>): Column<T['T']> {
     const rowCount = array.length;
-    const value: Column<T['T']>['value'] = schema.valueKind === 'str'
+    const value: Column<T['T']>['value'] = schema.valueType === 'str'
         ? row => { const v = array[row]; return typeof v === 'string' ? v : '' + v; }
         : row => array[row];
 
@@ -194,7 +195,7 @@ function arrayColumn<T extends Column.Schema>({ array, schema, valueKind }: Colu
         rowCount,
         value,
         valueKind: valueKind ? valueKind : row => Column.ValueKind.Present,
-        toArray: schema.valueKind === 'str'
+        toArray: schema.valueType === 'str'
             ? params => {
                 const { start, end } = ColumnHelpers.getArrayBounds(rowCount, params);
                 const ret = new (params && typeof params.array !== 'undefined' ? params.array : (array as any).constructor)(end - start) as any;
@@ -297,7 +298,7 @@ function mapToArrayImpl<T, S>(c: Column<T>, f: (v: T) => S, ctor: Column.ArrayCt
 }
 
 function areColumnsEqual(a: Column<any>, b: Column<any>) {
-    if (a.rowCount !== b.rowCount || a.isDefined !== b.isDefined || a.schema.valueKind !== b.schema.valueKind) return false;
+    if (a.rowCount !== b.rowCount || a.isDefined !== b.isDefined || a.schema.valueType !== b.schema.valueType) return false;
     if (!!a['@array'] && !!b['@array']) return areArraysEqual(a, b);
     return areValuesEqual(a, b);
 }
diff --git a/src/mol-io/reader/cif/schema.ts b/src/mol-io/reader/cif/schema.ts
index 8a538d9a3..1be7563d4 100644
--- a/src/mol-io/reader/cif/schema.ts
+++ b/src/mol-io/reader/cif/schema.ts
@@ -19,7 +19,7 @@ export function toTable<Schema extends Table.Schema, R extends Table<Schema> = T
 type ColumnCtor = (field: Data.Field, category: Data.Category, key: string) => Column<any>
 
 function getColumnCtor(t: Column.Schema): ColumnCtor {
-    switch (t.valueKind) {
+    switch (t.valueType) {
         case 'str': return (f, c, k) => createColumn(t, f, f.str, f.toStringArray);
         case 'int': return (f, c, k) => createColumn(t, f, f.int, f.toIntArray);
         case 'float': return (f, c, k) => createColumn(t, f, f.float, f.toFloatArray);
@@ -74,13 +74,13 @@ class CategoryTable implements Table<any> { // tslint:disable-line:class-name
             Object.defineProperty(this, k, {
                 get: function() {
                     if (cache[k]) return cache[k];
-                    const cType = schema[k];
-                    if (cType.valueKind === 'tensor') {
-                        cache[k] = createTensorColumn(cType, category, k);
+                    const fType = schema[k];
+                    if (fType.valueType === 'tensor') {
+                        cache[k] = createTensorColumn(fType, category, k);
                     } else {
-                        const ctor = getColumnCtor(cType);
+                        const ctor = getColumnCtor(fType);
                         const field = category.getField(k);
-                        cache[k] = !!field ? ctor(field, category, k) : Column.Undefined(category.rowCount, cType);
+                        cache[k] = !!field ? ctor(field, category, k) : Column.Undefined(category.rowCount, fType);
                     }
                     return cache[k];
                 },
diff --git a/src/mol-io/reader/common/text/column/fixed.ts b/src/mol-io/reader/common/text/column/fixed.ts
index 0a8477b31..7316f5234 100644
--- a/src/mol-io/reader/common/text/column/fixed.ts
+++ b/src/mol-io/reader/common/text/column/fixed.ts
@@ -16,15 +16,15 @@ export default function FixedColumnProvider(lines: Tokens) {
 
 export function FixedColumn<T extends Column.Schema>(lines: Tokens, offset: number, width: number, schema: T): Column<T['T']> {
     const { data, indices, count: rowCount } = lines;
-    const { valueKind: kind } = schema;
+    const { valueType: type } = schema;
 
-    const value: Column<T['T']>['value'] = kind === 'str' ? row => {
+    const value: Column<T['T']>['value'] = type === 'str' ? row => {
         let s = indices[2 * row] + offset, le = indices[2 * row + 1];
         if (s >= le) return '';
         let e = s + width;
         if (e > le) e = le;
         return trimStr(data, s, e);
-    } : kind === 'int' ? row => {
+    } : type === 'int' ? row => {
         const s = indices[2 * row] + offset;
         if (s > indices[2 * row + 1]) return 0;
         return parseIntSkipLeadingWhitespace(data, s, s + width);
diff --git a/src/mol-io/reader/common/text/column/token.ts b/src/mol-io/reader/common/text/column/token.ts
index 54bdef050..fb828354d 100644
--- a/src/mol-io/reader/common/text/column/token.ts
+++ b/src/mol-io/reader/common/text/column/token.ts
@@ -16,12 +16,12 @@ export default function TokenColumnProvider(tokens: Tokens) {
 
 export function TokenColumn<T extends Column.Schema>(tokens: Tokens, schema: T): Column<T['T']> {
     const { data, indices, count: rowCount } = tokens;
-    const { valueKind: kind } = schema;
+    const { valueType: type } = schema;
 
     const value: Column<T['T']>['value'] =
-          kind === 'str'
+          type === 'str'
         ? row => data.substring(indices[2 * row], indices[2 * row + 1])
-        : kind === 'int'
+        : type === 'int'
         ? row => fastParseInt(data, indices[2 * row], indices[2 * row + 1]) || 0
         : row => fastParseFloat(data, indices[2 * row], indices[2 * row + 1]) || 0;
 
diff --git a/src/mol-model/structure/export/mmcif.ts b/src/mol-model/structure/export/mmcif.ts
index 707c10491..09d54ab04 100644
--- a/src/mol-model/structure/export/mmcif.ts
+++ b/src/mol-model/structure/export/mmcif.ts
@@ -49,7 +49,7 @@ function ofSchema(schema: Table.Schema) {
     for (const k of Object.keys(schema)) {
         const t = schema[k];
         // TODO: matrix/vector/support
-        const type: any = t.valueKind === 'str' ? Encoder.FieldType.Str : t.valueKind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
+        const type: any = t.valueType === 'str' ? Encoder.FieldType.Str : t.valueType === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
         fields.push({ name: k, type, value: columnValue(k), valueKind: columnValueKind(k) })
     }
     return fields;
-- 
GitLab