Skip to content

Commit

Permalink
Update Flow to 0.139 & make checks pass
Browse files Browse the repository at this point in the history
  • Loading branch information
radex committed Dec 17, 2020
1 parent a5b33d1 commit 7b038b9
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ esproposal.optional_chaining=enable
emoji=true
module.ignore_non_literal_requires=true
module.file_ext=.js
types_first=false
well_formed_exports=false

[version]
>=0.86.0
>=0.108.0
7 changes: 1 addition & 6 deletions flow-typed/custom/lokijs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
declare module 'lokijs' {
declare module.exports: {
Loki: {...},
LokiResultset: {...},
LokiCollection: {...},
LokiMemoryAdpter: {...},
}
declare module.exports: any;
}

declare module 'lokijs/src/loki-indexed-adapter' {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"execa": "^2.0.0",
"fake-indexeddb": "^3.0.0",
"fast-async": "^7.0",
"flow-bin": "^0.109.0",
"flow-bin": "^0.139.0",
"fs-extra": "^8.0.0",
"glob-to-regexp": "^0.4.1",
"inquirer": "^7.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/DatabaseProvider/withDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import React from 'react'
import type Database from '../Database'
import { DatabaseConsumer } from './DatabaseContext'

type WithDatabaseProps<T> = {
...$Exact<T>,
type WithDatabaseProps<T: {}> = {
...T,
database: Database,
}
// HoC to inject the database into the props of consumers
export default function withDatabase<T>(
export default function withDatabase<T: {}>(
Component: React$ComponentType<WithDatabaseProps<T>>,
): React$ComponentType<T> {
return function DatabaseComponent(props): React$Element<*> {
Expand Down
3 changes: 2 additions & 1 deletion src/adapters/lokijs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

// don't import the whole utils/ here!
import type { LokiMemoryAdapter } from 'lokijs'
import type { LokiMemoryAdapter } from './type'
import invariant from '../../utils/common/invariant'
import logger from '../../utils/common/logger'
import type { ResultCallback } from '../../utils/fp/Result'
Expand Down Expand Up @@ -140,6 +140,7 @@ export default class LokiJSAdapter implements DatabaseAdapter {
// Copy
const lokiAdapter = executor.loki.persistenceAdapter

// $FlowFixMe
return new LokiJSAdapter({
...this._options,
dbName: this._dbName,
Expand Down
6 changes: 6 additions & 0 deletions src/adapters/lokijs/type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow

export type Loki = $FlowFixMe
export type LokiCollection = $FlowFixMe
export type LokiResultset = $FlowFixMe
export type LokiMemoryAdapter = $FlowFixMe
3 changes: 1 addition & 2 deletions src/adapters/lokijs/worker/executeQuery.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// @flow

import type Loki, { LokiResultset } from 'lokijs'

import type { SerializedQuery } from '../../../Query'

import type { DirtyRaw } from '../../../RawRecord'

import encodeQuery from './encodeQuery'
import performJoins from './performJoins'
import type { Loki, LokiResultset } from '../type'
import type { LokiJoin } from './encodeQuery'

// Finds IDs of matching records on foreign table
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/lokijs/worker/executor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow

// don't import the whole utils/ here!
import type Loki, { LokiCollection } from 'lokijs'
import logger from '../../../utils/common/logger'

import type { CachedQueryResult, CachedFindResult, BatchOperation } from '../../type'
Expand All @@ -15,6 +14,7 @@ import type {
import type { SerializedQuery } from '../../../Query'
import type { RecordId } from '../../../Model'
import { type RawRecord, sanitizedRaw, setRawSanitized, type DirtyRaw } from '../../../RawRecord'
import type { Loki, LokiCollection } from '../type'

import { newLoki, deleteDatabase, lokiFatalError } from './lokiExtensions'
import executeQuery from './executeQuery'
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/lokijs/worker/lokiExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* eslint-disable no-undef */

// don't import the whole utils/ here!
import type Loki from 'lokijs'
import logger from '../../../utils/common/logger'
import type { LokiAdapterOptions } from '../index'
import type { Loki } from '../type'

const isIDBAvailable = (onQuotaExceededError: ?(error: Error) => void) => {
return new Promise(resolve => {
Expand Down Expand Up @@ -59,6 +59,7 @@ async function getLokiAdapter(options: LokiAdapterOptions): mixed {
const IncrementalIDBAdapter = options._concurrentIdb ?
require('lokijs-concurrent-idb/src/incremental-indexeddb-adapter') :
require('lokijs/src/incremental-indexeddb-adapter')
// $FlowFixMe
return new IncrementalIDBAdapter({
onversionchange: onIndexedDBVersionChange,
onFetchStart: onIndexedDBFetchStart,
Expand All @@ -80,6 +81,7 @@ async function getLokiAdapter(options: LokiAdapterOptions): mixed {
export async function newLoki(options: LokiAdapterOptions): Loki {
const { autosave = true } = options
const LokiDb = options._concurrentIdb ? require('lokijs-concurrent-idb') : require('lokijs')
// $FlowFixMe
const loki: Loki = new LokiDb(options.dbName, {
adapter: await getLokiAdapter(options),
autosave,
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/sqlite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ export default class SQLiteAdapter implements DatabaseAdapter, SQLDatabaseAdapte
}

async testClone(options?: $Shape<SQLiteAdapterOptions> = {}): Promise<SQLiteAdapter> {
// $FlowFixMe
const clone = new SQLiteAdapter({
dbName: this._dbName,
schema: this.schema,
synchronous: this._dispatcherType === 'synchronous',
experimentalUseJSI: this._dispatcherType === 'jsi',
...(this.migrations ? { migrations: this.migrations } : {}),
// $FlowFixMe
...options,
})
invariant(
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/sqlite/makeDispatcher/node/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
const fs = require(`fs`)
const SQliteDatabase = require('better-sqlite3')

type SQLiteDatabaseType = any

class Database {
instance: SQliteDatabase = undefined
instance: $FlowFixMe<SQLiteDatabaseType> = undefined

path: string

Expand Down
1 change: 1 addition & 0 deletions src/sync/impl/applyRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export default function applyRemoteChanges(
): Promise<void> {
ensureActionsEnabled(db)
return db.action(async () => {
// $FlowFixMe
const recordsToApply = await getAllRecordsToApply(db, remoteChanges)

// Perform steps concurrently
Expand Down
2 changes: 2 additions & 0 deletions src/sync/impl/synchronize.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default async function synchronize({
)
log && (log.phase = 'ready to pull')

// $FlowFixMe
const { changes: remoteChanges, timestamp: newLastPulledAt } = await pullChanges({
lastPulledAt,
schemaVersion,
Expand Down Expand Up @@ -82,6 +83,7 @@ export default async function synchronize({

// push phase
log && (log.phase = 'ready to fetch local changes')
// $FlowFixMe
const localChanges = await fetchLocalChanges(database)
log && (log.localChangeCount = changeSetCount(localChanges.changes))
log && (log.phase = 'fetched local changes')
Expand Down
4 changes: 2 additions & 2 deletions src/utils/fp/checkName/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import type { TableName, ColumnName } from '../../../Schema'
// Note that this doesn't throw for Watermelon builtins (id, _changed, _status...)

const safeNameCharacters = /^[a-zA-Z_]\w*$/
const knownSafeNames = new Set()
const knownSafeNames: Set<string> = new Set()

export default function checkName<T: string | TableName<any> | ColumnName>(name: T): T {
if (knownSafeNames.has(name)) {
if (knownSafeNames.has((name: string))) {
return name
}

Expand Down
7 changes: 3 additions & 4 deletions src/utils/fp/isObject/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow

const isObject: <T>(T) => boolean = maybeObject =>
maybeObject !== null && typeof maybeObject === 'object' && !Array.isArray(maybeObject)

export default isObject
export default function isObject<T>(maybeObject: T): boolean {
return maybeObject !== null && typeof maybeObject === 'object' && !Array.isArray(maybeObject)
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3716,10 +3716,10 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==

flow-bin@^0.109.0:
version "0.109.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.109.0.tgz#dcdcb7402dd85b58200392d8716ccf14e5a8c24c"
integrity sha512-tpcMTpAGIRivYhFV3KJq+zHI2HzcXo8MoGe9pXS4G/UZuey2Faq/e8/gdph2WF0erRlML5hmwfwiq7v9c25c7w==
flow-bin@^0.139.0:
version "0.139.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.139.0.tgz#3ad6c75460be45b64f00521035c5affb3c440df5"
integrity sha512-eilVetLwztYtKjRj//4OsJ7aw47hsUZ8GTINxaZHWhpqiFikErQL0sV/3hQtpm54w9FuS2PO4yvbU0pWrtckqg==

for-in@^1.0.1, for-in@^1.0.2:
version "1.0.2"
Expand Down

0 comments on commit 7b038b9

Please sign in to comment.