Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): migrate run-sift to TS #25055

Merged
merged 6 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/gatsby/src/db/common/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ export interface IDbFilterStatement {
* structured representation of each distinct path of the query. We convert
* nested objects with multiple keys to separate instances.
*/
export function createDbQueriesFromObject(filter: object): Array<DbQuery> {
export function createDbQueriesFromObject(
filter: Record<string, any>
): Array<DbQuery> {
return createDbQueriesFromObjectNested(filter)
}

function createDbQueriesFromObjectNested(
filter: object,
filter: Record<string, any>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be Record<string, unknown>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the any to unknown triggers cascading errors. Are you sure that's the right way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be related to this:

packages/gatsby/src/db/common/query.ts:63:57 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'Record<string, unknown>'.

I hate that my editor throws different errors from yarn typecheck from whatever yarn format does. There should be one state :/

path: Array<string> = []
): Array<DbQuery> {
const keys = Object.getOwnPropertyNames(filter)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/db/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const _ = require(`lodash`)
const { store } = require(`../redux`)
const nodesDb: NodeStore = require(`../redux/nodes`)
const { runFastFiltersAndSort } = require(`../redux/run-sift`)
const { runFastFiltersAndSort } = require(`../redux/run-fast-filters`)

interface NodeStore {
getNodes: () => Array<any>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { runFastFiltersAndSort, applyFastFilters } = require(`../run-sift`)
const {
runFastFiltersAndSort,
applyFastFilters,
} = require(`../run-fast-filters`)
const { store } = require(`../index`)
const { createDbQueriesFromObject } = require(`../../db/common/query`)
const { actions } = require(`../actions`)
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/redux/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createPageDependency } from "./actions/add-page-dependency"
import { IDbQueryElemMatch } from "../db/common/query"

// Only list supported ops here. "CacheableFilterOp"
type FilterOp =
export type FilterOp = // TODO: merge with DbComparator ?
| "$eq"
| "$ne"
| "$lt"
Expand All @@ -15,7 +15,7 @@ type FilterOp =
| "$nin"
| "$regex" // Note: this includes $glob
// Note: `undefined` is an encoding for a property that does not exist
type FilterValueNullable =
export type FilterValueNullable = // TODO: merge with DbComparatorValue
| string
| number
| boolean
Expand Down
Loading