xdriver 1.0.8 → 1.0.9

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.
package/lib/Database.d.ts CHANGED
@@ -3,11 +3,13 @@ export default class Database {
3
3
  private name;
4
4
  private version;
5
5
  connect: any;
6
+ private initialized;
6
7
  readonly events: any;
7
8
  constructor(name: string, version?: number);
9
+ initialize(initialized: Function): this;
8
10
  on(event: any, fn?: Function): this;
9
11
  isOpen(): boolean;
10
- open(name?: string | undefined, version?: number | undefined): Promise<unknown>;
12
+ open(name?: any | undefined, version?: any): Promise<unknown>;
11
13
  drop(): Promise<unknown>;
12
14
  close(): void;
13
15
  createTable(tab: string | object, options?: object): Table;
package/lib/Database.js CHANGED
@@ -22,6 +22,14 @@ export default class Database {
22
22
  this.name = name;
23
23
  this.version = version;
24
24
  this.connect = null;
25
+ this.initialized = () => { };
26
+ }
27
+ initialize(initialized) {
28
+ if (this.isOpen()) {
29
+ throw new Error('You must be call this method before open');
30
+ }
31
+ this.initialized = initialized;
32
+ return this;
25
33
  }
26
34
  on(event, fn) {
27
35
  if (!_instance(event, Object)) {
@@ -39,6 +47,10 @@ export default class Database {
39
47
  return this.connect != null;
40
48
  }
41
49
  open(name, version) {
50
+ if (typeof name === "function") {
51
+ this.initialized = name;
52
+ name = undefined;
53
+ }
42
54
  this.name = name || this.name;
43
55
  this.version = version || this.version;
44
56
  const request = innerDB.open(this.name, version);
@@ -52,7 +64,7 @@ export default class Database {
52
64
  this.events.process(IndexdbStatus.CONNECT_CLOSE);
53
65
  this.events.close.call(this, e.target.result);
54
66
  };
55
- return new Promise((resolve) => {
67
+ return new Promise((resolve, reject) => {
56
68
  request.onsuccess = (e) => {
57
69
  this.connect = e.target.result;
58
70
  this.events.process(IndexdbStatus.CONNECT_SUCCESS);
@@ -68,7 +80,7 @@ export default class Database {
68
80
  this.events.process(IndexdbStatus.CONNECT_SUCCESS);
69
81
  this.connect = e.target.result;
70
82
  this.events.change.call(this, this.connect);
71
- resolve(this);
83
+ this.initialized();
72
84
  };
73
85
  });
74
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xdriver",
3
- "version": "1.0.08",
3
+ "version": "1.0.09",
4
4
  "description": "A simple driver for IndexDB",
5
5
  "main": "./lib/index",
6
6
  "files": [