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

Add plugin typings #768

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ See the [Sample section](#sample) for a sample with a more detailed explanation

## Announcements

- _Plugin typings from DefinitelyTyped are available in `types/index.d.ts` (community supported)_
- Using recent version of SQLite3 (`3.22.0`) with `SQLITE_DEFAULT_SYNCHRONOUS=3` (EXTRA DURABLE) build setting to be extra robust against possible database corruption ref: [litehelpers/Cordova-sqlite-storage#736](https://github.com/litehelpers/Cordova-sqlite-storage/issues/736)
- Nice overview of alternatives for storing local data in Cordova apps at: <https://www.sitepoint.com/storing-local-data-in-a-cordova-app/>
- New alternative solution for small data storage: [TheCocoaProject/ cordova-plugin-nativestorage](https://github.com/TheCocoaProject/cordova-plugin-nativestorage) - simpler "native storage of variables" for Android/iOS/Windows
Expand Down Expand Up @@ -1616,6 +1617,7 @@ function closeDB() {
- `scripts`: installation hook script to fetch the external dependencies via `npm`
- `spec`: test suite using Jasmine (`2.4.1`)
- `tests`: very simple Jasmine test suite that is run on Circle CI (Android platform) and Travis CI (iOS platform) (used as a placeholder)
- _`types/index.d.ts` by [@matrosov-nikita (Nikita Matrosov)](https://github.com/matrosov-nikita) (community support)_

<!-- END Source tree -->

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "cordova-sqlite-storage",
"version": "2.3.0",
"description": "Native interface to SQLite for PhoneGap/Cordova",
"types": "./types/index.d.ts",
"cordova": {
"id": "cordova-sqlite-storage",
"platforms": [
Expand Down
67 changes: 67 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Type definitions for cordova-sqlite-storage 1.5
// Project: https://github.com/litehelpers/Cordova-sqlite-storage
// Definitions by: rafw87 <https://github.com/rafw87/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

interface Window {
sqlitePlugin: SQLitePlugin.SQLite;
}

declare var sqlitePlugin: SQLitePlugin.SQLite;

declare namespace SQLitePlugin {
type TransactionFunction = (tx: Transaction) => void;

type SuccessCallback = () => void;
type DatabaseSuccessCallback = (db: Database) => void;
type StatementSuccessCallback = (results: Results) => void;
type TransactionStatementSuccessCallback = (tx: Transaction, results: Results) => void;

type ErrorCallback = (err: Error) => void;
type TransactionStatementErrorCallback = (tx: Transaction, err: Error) => boolean | void;

interface OpenArgs {
name: string;
location?: string;
iosDatabaseLocation?: string;
androidDatabaseImplementation?: number;
androidLockWorkaround?: number;
createFromLocation?: number;
[key: string]: any;
}
interface DeleteArgs {
name: string;
location?: string;
iosDatabaseLocation?: string;
}

interface Results {
rowsAffected: number;
insertId?: number;
rows: {
length: number;
item(i: number): any;
};
}

interface Transaction {
executeSql(statement: string, params?: any[], success?: TransactionStatementSuccessCallback, error?: TransactionStatementErrorCallback): void;
}

interface Database {
transaction(fn: TransactionFunction, error?: ErrorCallback, success?: SuccessCallback): void;
readTransaction(fn: TransactionFunction, error?: ErrorCallback, success?: SuccessCallback): void;

executeSql(statement: string, params?: any[], success?: StatementSuccessCallback, error?: ErrorCallback): void;
sqlBatch(sqlStatements: Array<string|[string, any[]]>, success?: SuccessCallback, error?: ErrorCallback): void;

close(success?: SuccessCallback, error?: ErrorCallback): void;
}

interface SQLite {
openDatabase(args: OpenArgs, success?: DatabaseSuccessCallback, error?: ErrorCallback): Database;
deleteDatabase(args: DeleteArgs, success?: SuccessCallback, error?: ErrorCallback): void;
selfTest(success?: SuccessCallback, error?: ErrorCallback): void;
echoTest(ok?: (value: string) => void, error?: (msg: string) => void): void;
}
}