diff --git a/src/Collection/RecordCache.d.ts b/src/Collection/RecordCache.d.ts index e406c6a16..6db8629cb 100644 --- a/src/Collection/RecordCache.d.ts +++ b/src/Collection/RecordCache.d.ts @@ -1,9 +1,9 @@ +import type { CachedQueryResult } from '../adapters/type' import type Model from '../Model' import type { RecordId } from '../Model' -import type Collection from './index' -import type { CachedQueryResult } from '../adapters/type' -import type { TableName } from '../Schema' import type { RawRecord } from '../RawRecord' +import type { TableName } from '../Schema' +import type Collection from './index' type Instantiator = (_: RawRecord) => T diff --git a/src/Collection/index.d.ts b/src/Collection/index.d.ts index af47bb402..2d298f537 100644 --- a/src/Collection/index.d.ts +++ b/src/Collection/index.d.ts @@ -1,22 +1,22 @@ // @flow -import { Observable, Subject } from '../utils/rx' -import type { ResultCallback } from '../utils/fp/Result' import type { ArrayOrSpreadFn } from '../utils/fp' +import type { ResultCallback } from '../utils/fp/Result' +import { Observable, Subject } from '../utils/rx' import type { Unsubscribe } from '../utils/subscriptions' -import Query from '../Query' import type Database from '../Database' import type Model from '../Model' import type { RecordId } from '../Model' +import Query from '../Query' import type { Clause } from '../QueryDescription' -import type { TableName, TableSchema } from '../Schema' import { DirtyRaw } from '../RawRecord' +import type { TableName, TableSchema } from '../Schema' import RecordCache from './RecordCache' type CollectionChangeType = 'created' | 'updated' | 'destroyed' -export type CollectionChange = { record: Record; type: CollectionChangeType } -export type CollectionChangeSet = CollectionChange[] +export interface CollectionChange { record: Record; type: CollectionChangeType } +export type CollectionChangeSet = Array> export default class Collection { database: Database diff --git a/src/Database/CollectionMap/index.d.ts b/src/Database/CollectionMap/index.d.ts index 44db903b7..62b69e709 100644 --- a/src/Database/CollectionMap/index.d.ts +++ b/src/Database/CollectionMap/index.d.ts @@ -1,5 +1,5 @@ -import type Model from '../../Model' import Collection from '../../Collection' +import type Model from '../../Model' import type { TableName } from '../../Schema' import type Database from '../index' diff --git a/src/Database/WorkQueue.d.ts b/src/Database/WorkQueue.d.ts index 3c4598d74..653fdedc1 100644 --- a/src/Database/WorkQueue.d.ts +++ b/src/Database/WorkQueue.d.ts @@ -1,6 +1,6 @@ import type Model from '../Model' -import type Database from './index' import { $ReadOnlyArray } from '../types'; +import type Database from './index' export interface ReaderInterface { callReader(reader: () => Promise): Promise; @@ -11,7 +11,7 @@ export interface WriterInterface extends ReaderInterface { batch(...records: $ReadOnlyArray): Promise; } -type WorkQueueItem = { +interface WorkQueueItem { work: (_: ReaderInterface | WriterInterface) => Promise; isWriter: boolean; resolve: (value: T) => void; diff --git a/src/Database/index.d.ts b/src/Database/index.d.ts index 861ed064e..5296f6a90 100644 --- a/src/Database/index.d.ts +++ b/src/Database/index.d.ts @@ -1,19 +1,19 @@ import type { Observable } from '../utils/rx' import { Unsubscribe } from '../utils/subscriptions' -import type { DatabaseAdapter } from '../adapters/type' import DatabaseAdapterCompat from '../adapters/compat' -import type Model from '../Model' +import type { DatabaseAdapter } from '../adapters/type' import type Collection from '../Collection' import type { CollectionChangeSet } from '../Collection' -import type { TableName, AppSchema } from '../Schema' +import type Model from '../Model' +import type { AppSchema, TableName } from '../Schema' import CollectionMap from './CollectionMap' import type LocalStorage from './LocalStorage' import WorkQueue from './WorkQueue' import type { ReaderInterface, WriterInterface } from './WorkQueue' -import { $ReadOnlyArray, $Exact, Class } from '../types' +import { $Exact, $ReadOnlyArray, Class } from '../types' type DatabaseProps = $Exact<{ adapter: DatabaseAdapter diff --git a/src/Query/index.d.ts b/src/Query/index.d.ts index 6193f18d6..67440fe9e 100644 --- a/src/Query/index.d.ts +++ b/src/Query/index.d.ts @@ -1,13 +1,13 @@ -import { Observable } from '../utils/rx' -import type { ArrayOrSpreadFn } from '../utils/fp' -import type { Unsubscribe, SharedSubscribable } from '../utils/subscriptions' import { $Exact } from '../types' +import type { ArrayOrSpreadFn } from '../utils/fp' +import { Observable } from '../utils/rx' +import type { SharedSubscribable, Unsubscribe } from '../utils/subscriptions' -import type { Clause, QueryDescription } from '../QueryDescription' +import type Collection from '../Collection' import type Model from '../Model' import type { AssociationInfo, RecordId } from '../Model' -import type Collection from '../Collection' -import type { TableName, ColumnName } from '../Schema' +import type { Clause, QueryDescription } from '../QueryDescription' +import type { ColumnName, TableName } from '../Schema' export type QueryAssociation = $Exact<{ from: TableName @@ -29,6 +29,20 @@ interface QueryCountProxy { } export default class Query { + + get count(): QueryCountProxy + + // MARK: - Internals + + get modelClass(): Record + + get table(): TableName + + get secondaryTables(): Array> + + get allTables(): Array> + + get associations(): QueryAssociation[] // Used by withObservables to differentiate between object types static _wmelonTag: string @@ -44,12 +58,12 @@ export default class Query { _cachedCountThrottledSubscribable: SharedSubscribable - // Note: Don't use this directly, use Collection.query(...) - constructor(collection: Collection, clauses: Clause[]) - // Creates a new Query that extends the clauses of this query extend: ArrayOrSpreadFn> + // Note: Don't use this directly, use Collection.query(...) + constructor(collection: Collection, clauses: Clause[]) + pipe(transform: (_: this) => T): T // Queries database and returns an array of matching records @@ -70,8 +84,6 @@ export default class Query { // Queries database and returns the number of matching records fetchCount(): Promise - get count(): QueryCountProxy - // Emits the number of matching records, then emits a new count every time it changes // Note: By default, the Observable is throttled! observeCount(isThrottled?: boolean): Observable @@ -98,18 +110,6 @@ export default class Query { // Destroys all records matching the query destroyAllPermanently(): Promise - // MARK: - Internals - - get modelClass(): Record - - get table(): TableName - - get secondaryTables(): TableName[] - - get allTables(): TableName[] - - get associations(): QueryAssociation[] - // Serialized version of Query (e.g. for sending to web worker) serialize(): SerializedQuery } diff --git a/src/QueryDescription/type.d.ts b/src/QueryDescription/type.d.ts index e4e868eba..80c806cd5 100644 --- a/src/QueryDescription/type.d.ts +++ b/src/QueryDescription/type.d.ts @@ -1,6 +1,6 @@ import type { $RE } from '../types' -import type { TableName, ColumnName } from '../Schema' +import type { ColumnName, TableName } from '../Schema' export type NonNullValue = number | string | boolean export type NonNullValues = number[] | string[] | boolean[] @@ -65,7 +65,7 @@ export type Skip = $RE<{ }> export type JoinTables = $RE<{ type: 'joinTables' - tables: TableName[] + tables: Array> }> export type NestedJoinTable = $RE<{ type: 'nestedJoinTable' @@ -95,7 +95,7 @@ export type Clause = type NestedJoinTableDef = $RE<{ from: TableName; to: TableName }> export type QueryDescription = $RE<{ where: Where[] - joinTables: TableName[] + joinTables: Array> nestedJoinTables: NestedJoinTableDef[] sortBy: SortBy[] take?: number diff --git a/src/RawRecord/index.d.ts b/src/RawRecord/index.d.ts index 54ce69bad..31c7b08bd 100644 --- a/src/RawRecord/index.d.ts +++ b/src/RawRecord/index.d.ts @@ -1,14 +1,14 @@ -import type { ColumnName, ColumnSchema, TableSchema } from '../Schema' import type { RecordId, SyncStatus } from '../Model' +import type { ColumnName, ColumnSchema, TableSchema } from '../Schema' // Raw object representing a model record, coming from an untrusted source // (disk, sync, user data). Before it can be used to create a Model instance // it must be sanitized (with `sanitizedRaw`) into a RawRecord -export type DirtyRaw = { [key: string]: any } +export interface DirtyRaw { [key: string]: any } // These fields are ALWAYS present in records of any collection. -type _RawRecord = { +interface _RawRecord { id: RecordId _status: SyncStatus _changed: string diff --git a/src/Relation/helpers.d.ts b/src/Relation/helpers.d.ts index aa6bf44a4..64261a36c 100644 --- a/src/Relation/helpers.d.ts +++ b/src/Relation/helpers.d.ts @@ -2,7 +2,7 @@ /* eslint-disable import/no-named-as-default */ import type { Observable } from '../utils/rx' -import type Relation from './index' import type Model from '../Model' +import type Relation from './index' export declare function createObservable(relation: Relation): Observable diff --git a/src/Relation/index.d.ts b/src/Relation/index.d.ts index e863d2afd..294e1d4b1 100644 --- a/src/Relation/index.d.ts +++ b/src/Relation/index.d.ts @@ -1,4 +1,4 @@ -import { $NonMaybeType, $Exact, $Call } from '../types' +import { $Call, $Exact, $NonMaybeType } from '../types' import type { Observable } from '../utils/rx' import type Model from '../Model' diff --git a/src/Schema/index.d.ts b/src/Schema/index.d.ts index 672013801..463091fbc 100644 --- a/src/Schema/index.d.ts +++ b/src/Schema/index.d.ts @@ -15,7 +15,7 @@ export type ColumnSchema = $RE<{ isIndexed?: boolean }> -export type ColumnMap = { [name: ColumnName]: ColumnSchema } +export interface ColumnMap { [name: ColumnName]: ColumnSchema } export type TableSchemaSpec = $Exact<{ name: TableName @@ -31,7 +31,7 @@ export type TableSchema = $RE<{ unsafeSql?: (_: string) => string }> -type TableMap = { [name: TableName]: TableSchema } +interface TableMap { [name: TableName]: TableSchema } export type SchemaVersion = number diff --git a/src/Schema/migrations/getSyncChanges/index.d.ts b/src/Schema/migrations/getSyncChanges/index.d.ts index 05f200252..edcc6c063 100644 --- a/src/Schema/migrations/getSyncChanges/index.d.ts +++ b/src/Schema/migrations/getSyncChanges/index.d.ts @@ -1,17 +1,17 @@ // @flow +import type { ColumnName, SchemaVersion, TableName } from '../../index' import type { SchemaMigrations } from '../index' -import type { TableName, ColumnName, SchemaVersion } from '../../index' import { $Exact } from '../../../types' export type MigrationSyncChanges = $Exact<{ from: SchemaVersion - tables: TableName[] - columns: $Exact<{ + tables: Array> + columns: Array<$Exact<{ table: TableName columns: ColumnName[] - }>[] + }>> }> | null export default function getSyncChanges( diff --git a/src/Schema/migrations/index.d.ts b/src/Schema/migrations/index.d.ts index 35f27f669..e06dd5212 100644 --- a/src/Schema/migrations/index.d.ts +++ b/src/Schema/migrations/index.d.ts @@ -1,5 +1,5 @@ -import type { $RE, $Exact } from '../../types' -import type { ColumnSchema, TableName, TableSchema, TableSchemaSpec, SchemaVersion } from '../index' +import type { $Exact, $RE } from '../../types' +import type { ColumnSchema, SchemaVersion, TableName, TableSchema, TableSchemaSpec } from '../index' export type CreateTableMigrationStep = $RE<{ type: 'create_table' diff --git a/src/Schema/migrations/stepsForMigration.d.ts b/src/Schema/migrations/stepsForMigration.d.ts index 9e0c367ac..b9429d0bf 100644 --- a/src/Schema/migrations/stepsForMigration.d.ts +++ b/src/Schema/migrations/stepsForMigration.d.ts @@ -1,7 +1,7 @@ import { $Exact } from '../../types' -import type { SchemaMigrations, MigrationStep } from './index' import type { SchemaVersion } from '../index' +import type { MigrationStep, SchemaMigrations } from './index' export function stepsForMigration({ migrations: schemaMigrations, diff --git a/src/adapters/compat.d.ts b/src/adapters/compat.d.ts index 51879c757..cdee52f8e 100644 --- a/src/adapters/compat.d.ts +++ b/src/adapters/compat.d.ts @@ -1,13 +1,13 @@ +import type { RecordId } from '../Model' import type { SerializedQuery } from '../Query' -import type { TableName, AppSchema } from '../Schema' +import type { AppSchema, TableName } from '../Schema' import type { SchemaMigrations } from '../Schema/migrations' -import type { RecordId } from '../Model' import type { - DatabaseAdapter, + BatchOperation, CachedFindResult, CachedQueryResult, - BatchOperation, + DatabaseAdapter, UnsafeExecuteOperations, } from './type' diff --git a/src/adapters/lokijs/common.d.ts b/src/adapters/lokijs/common.d.ts index 5528dc1ef..32cc9e517 100644 --- a/src/adapters/lokijs/common.d.ts +++ b/src/adapters/lokijs/common.d.ts @@ -1,7 +1,7 @@ -import { type Result } from '../../utils/fp/Result' -import type { CachedQueryResult, CachedFindResult } from '../type' import type { RecordId } from '../../Model' import { $Exact } from '../../types' +import { type Result } from '../../utils/fp/Result' +import type { CachedFindResult, CachedQueryResult } from '../type' export type WorkerExecutorType = | 'setUp' diff --git a/src/adapters/lokijs/dispatcher.d.ts b/src/adapters/lokijs/dispatcher.d.ts index a1e9c3ce5..20dc781ce 100644 --- a/src/adapters/lokijs/dispatcher.d.ts +++ b/src/adapters/lokijs/dispatcher.d.ts @@ -1,12 +1,12 @@ import type { ResultCallback } from '../../utils/fp/Result' import type { - WorkerExecutorType, + CloneMethod, WorkerExecutorPayload, + WorkerExecutorType, WorkerResponseData, - CloneMethod, } from './common' -type WorkerAction = { +interface WorkerAction { id: number, callback: ResultCallback, } diff --git a/src/adapters/lokijs/index.d.ts b/src/adapters/lokijs/index.d.ts index e09fb142f..dcbd56c9f 100644 --- a/src/adapters/lokijs/index.d.ts +++ b/src/adapters/lokijs/index.d.ts @@ -1,16 +1,16 @@ -import type { LokiMemoryAdapter } from './type' import type { ResultCallback } from '../../utils/fp/Result' +import type { LokiMemoryAdapter } from './type' import type { RecordId } from '../../Model' -import type { TableName, AppSchema } from '../../Schema' +import type { SerializedQuery } from '../../Query' import type { DirtyRaw } from '../../RawRecord' +import type { AppSchema, TableName } from '../../Schema' import type { SchemaMigrations } from '../../Schema/migrations' -import type { SerializedQuery } from '../../Query' import type { - DatabaseAdapter, - CachedQueryResult, - CachedFindResult, BatchOperation, + CachedFindResult, + CachedQueryResult, + DatabaseAdapter, UnsafeExecuteOperations, } from '../type' @@ -63,7 +63,7 @@ export type LokiAdapterOptions = $Exact<{ onFetchStart?: () => void // Collections (by table name) that Loki should deserialize lazily. This is only profitable for // collections that are most likely not required for launch - making everything lazy makes it slower - lazyCollections?: TableName[] + lazyCollections?: Array> }> // -- internal -- _testLokiAdapter?: LokiMemoryAdapter diff --git a/src/adapters/sqlite/index.d.ts b/src/adapters/sqlite/index.d.ts index 88c43a024..49c3eae27 100644 --- a/src/adapters/sqlite/index.d.ts +++ b/src/adapters/sqlite/index.d.ts @@ -3,23 +3,23 @@ import type { ResultCallback } from '../../utils/fp/Result' import type { RecordId } from '../../Model' import type { SerializedQuery } from '../../Query' -import type { TableName, AppSchema, SchemaVersion } from '../../Schema' -import type { SchemaMigrations, MigrationStep } from '../../Schema/migrations' +import type { AppSchema, SchemaVersion, TableName } from '../../Schema' +import type { MigrationStep, SchemaMigrations} from '../../Schema/migrations' import type { - DatabaseAdapter, - CachedQueryResult, - CachedFindResult, BatchOperation, + CachedFindResult, + CachedQueryResult, + DatabaseAdapter, UnsafeExecuteOperations, } from '../type' import type { DispatcherType, + MigrationEvents, SQL, SQLiteAdapterOptions, SQLiteArg, - SQLiteQuery, SqliteDispatcher, - MigrationEvents, + SQLiteQuery, } from './type' import { $Shape } from '../../types' diff --git a/src/decorators/relation/index.d.ts b/src/decorators/relation/index.d.ts index d2b8fa81e..d0f3198a1 100644 --- a/src/decorators/relation/index.d.ts +++ b/src/decorators/relation/index.d.ts @@ -1,5 +1,5 @@ -import { ColumnName, TableName } from '../../Schema' import { Options } from '../../Relation' +import { ColumnName, TableName } from '../../Schema' declare function relation( relationTable: TableName, diff --git a/src/observation/subscribeToCount/index.d.ts b/src/observation/subscribeToCount/index.d.ts index 560cb57cd..f3cfb543f 100644 --- a/src/observation/subscribeToCount/index.d.ts +++ b/src/observation/subscribeToCount/index.d.ts @@ -3,8 +3,8 @@ import type { Unsubscribe } from '../../utils/subscriptions' -import type Query from '../../Query' import type Model from '../../Model' +import type Query from '../../Query' export function experimentalDisableObserveCountThrottling(): void diff --git a/src/observation/subscribeToQueryReloading/index.d.ts b/src/observation/subscribeToQueryReloading/index.d.ts index 16a15467a..6f3e4d3e3 100644 --- a/src/observation/subscribeToQueryReloading/index.d.ts +++ b/src/observation/subscribeToQueryReloading/index.d.ts @@ -2,8 +2,8 @@ /* eslint-disable import/no-named-as-default */ import type { Unsubscribe } from '../../utils/subscriptions' -import type Query from '../../Query' import type Model from '../../Model' +import type Query from '../../Query' // Produces an observable version of a query by re-querying the database // when any change occurs in any of the relevant Stores. diff --git a/src/react/DatabaseProvider.d.ts b/src/react/DatabaseProvider.d.ts index c87ccb19e..d9968b15b 100644 --- a/src/react/DatabaseProvider.d.ts +++ b/src/react/DatabaseProvider.d.ts @@ -1,7 +1,7 @@ import { ReactNode } from 'react' import Database from '../Database' -export type Props = { +export interface Props { database: Database children: ReactNode } diff --git a/src/react/withDatabase.d.ts b/src/react/withDatabase.d.ts index 3dffd74d0..270e32424 100644 --- a/src/react/withDatabase.d.ts +++ b/src/react/withDatabase.d.ts @@ -1,5 +1,5 @@ -import * as React from 'react' import { NonReactStatics } from 'hoist-non-react-statics' +import * as React from 'react' import type Database from '../Database' type WithDatabaseProps = T & { @@ -13,4 +13,4 @@ export default function withDatabase< C extends React.ComponentType, P = GetProps, R = Omit ->(Component: C): React.FunctionComponent & NonReactStatics \ No newline at end of file +>(Component: C): React.FunctionComponent & NonReactStatics diff --git a/src/sync/impl/applyRemote.d.ts b/src/sync/impl/applyRemote.d.ts index 32b5a8ad0..38eaaa1ca 100644 --- a/src/sync/impl/applyRemote.d.ts +++ b/src/sync/impl/applyRemote.d.ts @@ -1,6 +1,6 @@ import type { Database } from '../..' -import type { SyncDatabaseChangeSet, SyncLog, SyncConflictResolver } from '../index' +import type { SyncConflictResolver, SyncDatabaseChangeSet, SyncLog } from '../index' export default function applyRemoteChanges( remoteChanges: SyncDatabaseChangeSet, diff --git a/src/sync/impl/helpers.d.ts b/src/sync/impl/helpers.d.ts index 746efbc87..b1765ec51 100644 --- a/src/sync/impl/helpers.d.ts +++ b/src/sync/impl/helpers.d.ts @@ -1,6 +1,6 @@ -import type { Model, Collection, Database } from '../..' -import type { RawRecord, DirtyRaw } from '../../RawRecord' -import type { SyncLog, SyncDatabaseChangeSet, SyncConflictResolver } from '../index' +import type { Collection, Database, Model } from '../..' +import type { DirtyRaw, RawRecord } from '../../RawRecord' +import type { SyncConflictResolver, SyncDatabaseChangeSet, SyncLog } from '../index' // Returns raw record with naive solution to a conflict based on local `_changed` field // This is a per-column resolution algorithm. All columns that were changed locally win diff --git a/src/sync/impl/index.d.ts b/src/sync/impl/index.d.ts index 865a0e87f..6b8c29f4a 100644 --- a/src/sync/impl/index.d.ts +++ b/src/sync/impl/index.d.ts @@ -1,9 +1,9 @@ -import { $Exact } from '../../types' import type { Database } from '../..' +import { $Exact } from '../../types' -import type { Timestamp, SyncLog } from '../index' import type { SchemaVersion } from '../../Schema' import type { MigrationSyncChanges } from '../../Schema/migrations/getSyncChanges' +import type { SyncLog, Timestamp } from '../index' export { default as applyRemoteChanges } from './applyRemote' export { default as fetchLocalChanges, hasUnsyncedChanges } from './fetchLocal' diff --git a/src/types.d.ts b/src/types.d.ts index 6587e4df8..e65051fdc 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -8,7 +8,7 @@ export type $Exact = Type export type $RE = Readonly<$Exact> -export type $Keys = { k: keyof Type } +export interface $Keys { k: keyof Type } export type Array = Type[] diff --git a/tslint.json b/tslint.json index 5f00d0c19..fc302ae9e 100644 --- a/tslint.json +++ b/tslint.json @@ -7,7 +7,10 @@ "rules": { "interface-name": false, "jsdoc-format": false, - "member-access": false + "member-access": false, + "variable-name": { + "options": ["check-format", "allow-leading-underscore"] + } }, "rulesDirectory": [] -} \ No newline at end of file +}