@sqlitecloud/drivers 1.0.400 → 1.0.417

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
- import { SQLiteCloudConfig, RowCountCallback, SQLiteCloudCommand } from './types';
2
- import { ErrorCallback, ResultsCallback, RowCallback, RowsCallback } from './types';
3
1
  import EventEmitter from 'eventemitter3';
4
2
  import { PubSub } from './pubsub';
5
3
  import { Statement } from './statement';
4
+ import { ErrorCallback, ResultsCallback, RowCallback, RowCountCallback, RowsCallback, SQLiteCloudCommand, SQLiteCloudConfig } from './types';
6
5
  /**
7
6
  * Creating a Database object automatically opens a connection to the SQLite database.
8
7
  * When the connection is established the Database object emits an open event and calls
@@ -152,6 +151,10 @@ export declare class Database extends EventEmitter {
152
151
  * metadata in case of insert, update, delete.
153
152
  */
154
153
  sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: any[]): Promise<any>;
154
+ /**
155
+ * Returns true if the database connection is open.
156
+ */
157
+ isConnected(): boolean;
155
158
  /**
156
159
  * PubSub class provides a Pub/Sub real-time updates and notifications system to
157
160
  * allow multiple applications to communicate with each other asynchronously.
@@ -49,13 +49,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.Database = void 0;
52
- const rowset_1 = require("./rowset");
53
- const types_1 = require("./types");
54
- const utilities_1 = require("./utilities");
52
+ // Trying as much as possible to be a drop-in replacement for SQLite3 API
53
+ // https://github.com/TryGhost/node-sqlite3/wiki/API
54
+ // https://github.com/TryGhost/node-sqlite3
55
+ // https://github.com/TryGhost/node-sqlite3/blob/master/lib/sqlite3.d.ts
55
56
  const eventemitter3_1 = __importDefault(require("eventemitter3"));
56
- const utilities_2 = require("./utilities");
57
57
  const pubsub_1 = require("./pubsub");
58
+ const rowset_1 = require("./rowset");
58
59
  const statement_1 = require("./statement");
60
+ const types_1 = require("./types");
61
+ const utilities_1 = require("./utilities");
59
62
  // Uses eventemitter3 instead of node events for browser compatibility
60
63
  // https://github.com/primus/eventemitter3
61
64
  /**
@@ -96,7 +99,7 @@ class Database extends eventemitter3_1.default {
96
99
  }
97
100
  else {
98
101
  // connect using websocket if tls is not supported or if explicitly requested
99
- const useWebsocket = utilities_2.isBrowser || ((_b = this.config) === null || _b === void 0 ? void 0 : _b.usewebsocket) || ((_c = this.config) === null || _c === void 0 ? void 0 : _c.gatewayurl);
102
+ const useWebsocket = utilities_1.isBrowser || ((_b = this.config) === null || _b === void 0 ? void 0 : _b.usewebsocket) || ((_c = this.config) === null || _c === void 0 ? void 0 : _c.gatewayurl);
100
103
  if (useWebsocket) {
101
104
  // socket.io transport works in both node.js and browser environments and connects via SQLite Cloud Gateway
102
105
  Promise.resolve().then(() => __importStar(require('./connection-ws'))).then(module => {
@@ -453,6 +456,13 @@ class Database extends eventemitter3_1.default {
453
456
  });
454
457
  });
455
458
  }
459
+ /**
460
+ * Returns true if the database connection is open.
461
+ */
462
+ isConnected() {
463
+ var _a;
464
+ return ((_a = this.connections) === null || _a === void 0 ? void 0 : _a.length) > 0 && this.connections[0].connected;
465
+ }
456
466
  /**
457
467
  * PubSub class provides a Pub/Sub real-time updates and notifications system to
458
468
  * allow multiple applications to communicate with each other asynchronously.
@@ -17,6 +17,8 @@ export declare function getUpdateResults(results?: any): Record<string, any> | u
17
17
  * containing the arguments array with the callbacks removed (if any), and the callback itself.
18
18
  * If there are multiple callbacks, the first one is returned as 'callback' and the last one
19
19
  * as 'completeCallback'.
20
+ *
21
+ * @returns args is a simple list of SQLiteCloudDataTypes, we flat them into a single array
20
22
  */
21
23
  export declare function popCallback<T extends ErrorCallback = ErrorCallback>(args: (SQLiteCloudDataTypes | T | ErrorCallback)[]): {
22
24
  args: SQLiteCloudDataTypes[];
@@ -124,6 +124,8 @@ function getUpdateResults(results) {
124
124
  * containing the arguments array with the callbacks removed (if any), and the callback itself.
125
125
  * If there are multiple callbacks, the first one is returned as 'callback' and the last one
126
126
  * as 'completeCallback'.
127
+ *
128
+ * @returns args is a simple list of SQLiteCloudDataTypes, we flat them into a single array
127
129
  */
128
130
  function popCallback(args) {
129
131
  const remaining = args;
@@ -131,11 +133,11 @@ function popCallback(args) {
131
133
  if (args && args.length > 0 && typeof args[args.length - 1] === 'function') {
132
134
  // at least 2 callbacks?
133
135
  if (args.length > 1 && typeof args[args.length - 2] === 'function') {
134
- return { args: remaining.slice(0, -2), callback: args[args.length - 2], complete: args[args.length - 1] };
136
+ return { args: remaining.slice(0, -2).flat(), callback: args[args.length - 2], complete: args[args.length - 1] };
135
137
  }
136
- return { args: remaining.slice(0, -1), callback: args[args.length - 1] };
138
+ return { args: remaining.slice(0, -1).flat(), callback: args[args.length - 1] };
137
139
  }
138
- return { args: remaining };
140
+ return { args: remaining.flat() };
139
141
  }
140
142
  //
141
143
  // configuration validation