Added typings to annoMatrix dir. (#2365) (#2371)

* Added typings to annoMatrix directory. (#2365)

* Added review point updates. (#2365)

* Fixed viewOf defect. Added review point updates. (#2365)

* Updated test to use Field key interpolation. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>

* Updated test to use Field key interpolation. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>

* Updated test to use Field key interpolation. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>

* Updated test to use Field key interpolation. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>

* Linting. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>

* Simplified while condition in middleware GC. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>

* Reverted embedding.ts prettier to resolve conflict. (#2365)

Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
This commit is contained in:
Mim Hastie
2021-08-18 13:18:54 -07:00
committed by GitHub
co-authored by Timmy Huang
parent 08b03ace60
commit b814489328
19 changed files with 1121 additions and 948 deletions
@@ -4,31 +4,34 @@ import {
_whereCacheCreate,
_whereCacheMerge,
} from "../../../src/annoMatrix/whereCache";
import { Field, Schema } from "../../../src/common/types/schema";
import { Query } from "../../../src/annoMatrix/query";
const schema = {};
const schema = {} as Schema;
describe("whereCache", () => {
test("whereCacheGet - where query, missing cache values", () => {
expect(
_whereCacheGet({}, schema, "X", {
_whereCacheGet({}, schema, Field.X, {
where: {
field: "var",
field: Field.var,
column: "foo",
value: "bar",
},
})
).toEqual([undefined]);
expect(
_whereCacheGet({}, schema, "X", {
_whereCacheGet({}, schema, Field.X, {
summarize: {
field: "var",
method: "mean",
field: Field.var,
column: "foo",
values: ["bar"],
},
})
).toEqual([undefined]);
expect(
_whereCacheGet({ where: { X: {} } }, schema, "X", {
_whereCacheGet({ where: { X: {} } }, schema, Field.X, {
where: {
field: "var",
column: "foo",
@@ -37,7 +40,7 @@ describe("whereCache", () => {
})
).toEqual([undefined]);
expect(
_whereCacheGet({ where: { X: { var: new Map() } } }, schema, "X", {
_whereCacheGet({ where: { X: { var: new Map() } } }, schema, Field.X, {
where: {
field: "var",
column: "foo",
@@ -49,7 +52,7 @@ describe("whereCache", () => {
_whereCacheGet(
{ where: { X: { var: new Map([["foo", new Map()]]) } } },
schema,
"X",
Field.X,
{
where: {
field: "var",
@@ -63,7 +66,7 @@ describe("whereCache", () => {
test("whereCacheGet - summarize query, missing cache values", () => {
expect(
_whereCacheGet({}, schema, "X", {
_whereCacheGet({}, schema, Field.X, {
summarize: {
method: "mean",
field: "var",
@@ -76,7 +79,7 @@ describe("whereCache", () => {
_whereCacheGet(
{ summarize: { X: { mean: { var: new Map() } } } },
schema,
"X",
Field.X,
{
summarize: {
method: "mean",
@@ -122,7 +125,7 @@ describe("whereCache", () => {
};
expect(
_whereCacheGet(whereCache, schema, "X", {
_whereCacheGet(whereCache, schema, Field.X, {
where: {
field: "var",
column: "foo",
@@ -131,7 +134,7 @@ describe("whereCache", () => {
})
).toEqual([0]);
expect(
_whereCacheGet(whereCache, schema, "X", {
_whereCacheGet(whereCache, schema, Field.X, {
summarize: {
method: "mean",
field: "var",
@@ -141,7 +144,7 @@ describe("whereCache", () => {
})
).toEqual([0]);
expect(
_whereCacheGet(whereCache, schema, "X", {
_whereCacheGet(whereCache, schema, Field.X, {
where: {
field: "var",
column: "foo",
@@ -150,7 +153,7 @@ describe("whereCache", () => {
})
).toEqual([1, 2]);
expect(
_whereCacheGet(whereCache, schema, "X", {
_whereCacheGet(whereCache, schema, Field.X, {
summarize: {
method: "mean",
field: "var",
@@ -159,9 +162,12 @@ describe("whereCache", () => {
},
})
).toEqual([1, 2]);
expect(_whereCacheGet(whereCache, schema, "Y", {})).toEqual([undefined]);
expect(
_whereCacheGet(whereCache, schema, "X", {
// Force invalid field value Y
_whereCacheGet(whereCache, schema, "Y" as Field, {} as Query)
).toEqual([undefined]);
expect(
_whereCacheGet(whereCache, schema, Field.X, {
where: {
field: "whoknows",
column: "whatever",
@@ -170,7 +176,7 @@ describe("whereCache", () => {
})
).toEqual([undefined]);
expect(
_whereCacheGet(whereCache, schema, "X", {
_whereCacheGet(whereCache, schema, Field.X, {
where: {
field: "var",
column: "whatever",
@@ -179,7 +185,7 @@ describe("whereCache", () => {
})
).toEqual([undefined]);
expect(
_whereCacheGet(whereCache, schema, "X", {
_whereCacheGet(whereCache, schema, Field.X, {
where: {
field: "var",
column: "foo",
@@ -198,7 +204,7 @@ describe("whereCache", () => {
},
};
const wc = _whereCacheCreate(
"field",
Field.obs,
{
where: {
field: "queryField",
@@ -212,7 +218,7 @@ describe("whereCache", () => {
expect(wc).toEqual(
expect.objectContaining({
where: {
field: {
[Field.obs]: {
queryField: expect.any(Map),
},
},
@@ -220,18 +226,19 @@ describe("whereCache", () => {
);
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
expect((wc.where as any).field.queryField.has("queryColumn")).toEqual(true);
expect((wc.where as any)[Field.obs].queryField.has("queryColumn")).toEqual(true);
expect(
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
(wc.where as any).field.queryField.get("queryColumn")
(wc.where as any)[Field.obs].queryField.get("queryColumn")
).toBeInstanceOf(Map);
expect(
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
(wc.where as any).field.queryField.get("queryColumn").has("queryValue")
(wc.where as any)[Field.obs].queryField.get("queryColumn").has("queryValue")
).toEqual(true);
expect(_whereCacheGet(wc, schema, "field", query)).toEqual([0, 1, 2]);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
expect(_whereCacheGet(wc!, schema, Field.obs, query)).toEqual([0, 1, 2]);
});
test("whereCacheCreate, summarize query", () => {
@@ -243,12 +250,14 @@ describe("whereCache", () => {
values: ["queryValue"],
},
};
const wc = _whereCacheCreate("field", query, [0, 1, 2]);
expect(_whereCacheGet(wc, schema, "field", query)).toEqual([0, 1, 2]);
const wc = _whereCacheCreate(Field.obs, query, [0, 1, 2]);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
expect(_whereCacheGet(wc!, schema, Field.obs, query)).toEqual([0, 1, 2]);
});
test("whereCacheCreate, unknown query type", () => {
expect(_whereCacheCreate("field", { foobar: true }, [1])).toEqual({});
// @ts-expect-error --- force invalid query {foobar: true}
expect(_whereCacheCreate(Field.obs, { foobar: true }, [1])).toEqual({});
});
test("whereCacheMerge, where queries", () => {
@@ -256,19 +265,20 @@ describe("whereCache", () => {
// remember, will mutate dst
const src = _whereCacheCreate(
"field",
Field.obs,
{ where: { field: "queryField", column: "queryColumn", value: "foo" } },
["foo"]
);
const dst1 = _whereCacheCreate(
"field",
Field.obs,
{ where: { field: "queryField", column: "queryColumn", value: "bar" } },
["dst1"]
);
wc = _whereCacheMerge(dst1, src);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert dst1 and src to be non-null
wc = _whereCacheMerge(dst1!, src!);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
where: {
field: "queryField",
column: "queryColumn",
@@ -277,7 +287,7 @@ describe("whereCache", () => {
})
).toEqual(["foo"]);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
where: {
field: "queryField",
column: "queryColumn",
@@ -287,13 +297,14 @@ describe("whereCache", () => {
).toEqual(["dst1"]);
const dst2 = _whereCacheCreate(
"field",
Field.obs,
{ where: { field: "queryField", column: "queryColumn", value: "bar" } },
["dst2"]
);
wc = _whereCacheMerge(dst2, dst1, src);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert dst2m, dst1 and src to be non-null
wc = _whereCacheMerge(dst2!, dst1!, src!);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
where: {
field: "queryField",
column: "queryColumn",
@@ -302,7 +313,7 @@ describe("whereCache", () => {
})
).toEqual(["foo"]);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
where: {
field: "queryField",
column: "queryColumn",
@@ -311,17 +322,20 @@ describe("whereCache", () => {
})
).toEqual(["dst1"]);
wc = _whereCacheMerge({}, src);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert src to be non-null
wc = _whereCacheMerge({}, src!);
expect(wc).toEqual(src);
wc = _whereCacheMerge({ where: { field: { queryField: new Map() } } }, src);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert src to be non-null
wc = _whereCacheMerge({ where: { obs: { queryField: new Map() } } }, src!);
expect(wc).toEqual(src);
});
test("whereCacheMerge, mixed queries", () => {
const wc = _whereCacheMerge(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
_whereCacheCreate(
"field",
Field.obs,
{
where: {
field: "queryField",
@@ -330,9 +344,10 @@ describe("whereCache", () => {
},
},
["a"]
),
)!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
_whereCacheCreate(
"field",
Field.obs,
{
summarize: {
method: "mean",
@@ -342,11 +357,11 @@ describe("whereCache", () => {
},
},
["b"]
)
)!
);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
where: {
field: "queryField",
column: "queryColumn",
@@ -356,7 +371,7 @@ describe("whereCache", () => {
).toEqual(["a"]);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
summarize: {
method: "mean",
field: "queryField",
@@ -367,7 +382,7 @@ describe("whereCache", () => {
).toEqual(["b"]);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
where: {
field: "queryField",
column: "queryColumn",
@@ -377,7 +392,7 @@ describe("whereCache", () => {
).toEqual([undefined]);
expect(
_whereCacheGet(wc, schema, "field", {
_whereCacheGet(wc, schema, Field.obs, {
summarize: {
method: "no-such-method",
field: "queryField",