mol_db 0.0.45
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/.nojekyll +0 -0
- package/README.md +178 -0
- package/node.audit.js +1 -0
- package/node.d.ts +114 -0
- package/node.deps.json +1 -0
- package/node.esm.js +253 -0
- package/node.esm.js.map +1 -0
- package/node.js +252 -0
- package/node.js.map +1 -0
- package/node.test.js +1962 -0
- package/node.test.js.map +1 -0
- package/package.json +12 -0
- package/test.html +17 -0
- package/web.audit.js +1 -0
- package/web.css +1 -0
- package/web.css.map +1 -0
- package/web.d.ts +114 -0
- package/web.deps.json +1 -0
- package/web.esm.js +253 -0
- package/web.esm.js.map +1 -0
- package/web.js +252 -0
- package/web.js.map +1 -0
- package/web.test.js +1003 -0
- package/web.test.js.map +1 -0
package/.nojekyll
ADDED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# $mol_db
|
|
2
|
+
|
|
3
|
+
Static typed facade for [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) with simple API.
|
|
4
|
+
|
|
5
|
+
## IndexedDB Structure
|
|
6
|
+
|
|
7
|
+
- **Database** contains named Stores
|
|
8
|
+
- - **Store** contains Documents by primary keys and named Indexes
|
|
9
|
+
- - - **Document** contains any data
|
|
10
|
+
- - - **Index** points to Documents
|
|
11
|
+
|
|
12
|
+
## DB life Cycle
|
|
13
|
+
|
|
14
|
+
### DB Schema Example
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
type ACME = {
|
|
18
|
+
Users: {
|
|
19
|
+
Key: number
|
|
20
|
+
Doc: {
|
|
21
|
+
name: {
|
|
22
|
+
first: string
|
|
23
|
+
last: string
|
|
24
|
+
}
|
|
25
|
+
age: number
|
|
26
|
+
}
|
|
27
|
+
Indexes: {
|
|
28
|
+
names: [ string, string ]
|
|
29
|
+
ages: [ number ]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
Articles: {
|
|
33
|
+
Key: string
|
|
34
|
+
Doc: {
|
|
35
|
+
title: string
|
|
36
|
+
content: string
|
|
37
|
+
}
|
|
38
|
+
Indexes: {
|
|
39
|
+
full: [ string, string ]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Open DB without Migrations
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const db = await $$.$mol_db< ACME >( 'ACME' )
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Open DB with automatic migrations
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
const db = await $$.$mol_db< ACME >( 'ACME',
|
|
55
|
+
mig => mig.store_make( 'Users' )
|
|
56
|
+
mig => mig.stores.Users.index_make( 'ages', [ 'age' ] )
|
|
57
|
+
mig => mig.stores.Users.index_make( 'names', [ 'name.first', 'name.last' ], !!'unique' )
|
|
58
|
+
mig => mig.store_make( 'Articles' )
|
|
59
|
+
mig => mig.stores.Articles.index_make( 'full', [ 'title', 'content' ] )
|
|
60
|
+
// mig => mig.stores.Articles.index_drop( 'full' )
|
|
61
|
+
// mig => mig.store_drop( 'Articles' )
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
There is 5 migrations. And DB version is 6. After uncommenting last 2 rows, it applies 2 additional migrations and DB version will be 8.
|
|
66
|
+
|
|
67
|
+
### Close DB Connection
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
db.destructor()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Delete DB
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
db.kill()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Transaction Life Cycle
|
|
80
|
+
|
|
81
|
+
### Read Only Transactions
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const { Users, Articles } = db.read( 'Users', 'Articles' )
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Read/Write Trasactions
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const trans = db.change( 'Users', 'Articles' )
|
|
91
|
+
const { Users, Articles } = trans.stores
|
|
92
|
+
|
|
93
|
+
// ...
|
|
94
|
+
|
|
95
|
+
trans.abort()
|
|
96
|
+
// or
|
|
97
|
+
await trans.commit()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Uncommited transaction without errors will be commitetd automatically. Any modification error aborts transaction.
|
|
101
|
+
|
|
102
|
+
## Documents Life Cycle
|
|
103
|
+
|
|
104
|
+
### By Primary key
|
|
105
|
+
|
|
106
|
+
#### Insert with Auto Incremental Primary Key
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
const key = await Users.put({
|
|
110
|
+
first: 'Jin',
|
|
111
|
+
last: 'Nin',
|
|
112
|
+
age: 36,
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Put/Overwrite by Primary Key
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
await Users.put( {
|
|
120
|
+
first: 'Jin',
|
|
121
|
+
last: 'Nin',
|
|
122
|
+
age: 37,
|
|
123
|
+
}, 1 )
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Get One By Primary Key
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const user = await Users.get( 1 )
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Select 10 By Primary Keys
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const users = await Users.get( IDBKeyRange.bound( 10, 50 ), 10 )
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Count By Primary Keys
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const count = await Users.count( IDBKeyRange.bound( 10, 50 ) )
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### By Index
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const { names, ages } = users.indexes
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Get One By Index
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const user = await names.get([ 'Jin', 'Nin' ])
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Select 10 By Index
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const users = await ages.get( [ 18 ], 10 )
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Count By Primary Keys
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const count = await Users.count([ 18 ])
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Usage from NPM
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
npm install mol_db
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
[](https://bundlephobia.com/package/mol_db)
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
import { $mol_db } from 'mol_db'
|
|
178
|
+
```
|
package/node.audit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.info("Audit passed")
|
package/node.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
declare let _$_: {
|
|
2
|
+
new (): {};
|
|
3
|
+
} & typeof globalThis;
|
|
4
|
+
declare class $ extends _$_ {
|
|
5
|
+
}
|
|
6
|
+
declare namespace $ {
|
|
7
|
+
export type $ = typeof $$;
|
|
8
|
+
export class $$ extends $ {
|
|
9
|
+
}
|
|
10
|
+
namespace $$ {
|
|
11
|
+
type $$ = $;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare namespace $ {
|
|
17
|
+
function $mol_db_response<Result>(request: IDBRequest<Result>): Promise<Result>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare namespace $ {
|
|
21
|
+
class $mol_db_store<Schema extends $mol_db_store_schema> {
|
|
22
|
+
readonly native: IDBObjectStore;
|
|
23
|
+
constructor(native: IDBObjectStore);
|
|
24
|
+
get name(): string;
|
|
25
|
+
get path(): string | string[];
|
|
26
|
+
get incremental(): boolean;
|
|
27
|
+
get indexes(): { [Name in keyof Schema["Indexes"]]: $mol_db_index<{
|
|
28
|
+
Key: Schema["Indexes"][Name];
|
|
29
|
+
Doc: Schema['Doc'];
|
|
30
|
+
}>; };
|
|
31
|
+
index_make(name: string, path?: string[], unique?: boolean, multiEntry?: boolean): IDBIndex;
|
|
32
|
+
index_drop(name: string): this;
|
|
33
|
+
get transaction(): $mol_db_transaction<$mol_db_schema>;
|
|
34
|
+
get db(): $mol_db_database<$mol_db_schema>;
|
|
35
|
+
clear(): Promise<undefined>;
|
|
36
|
+
count(keys?: Schema['Key'] | IDBKeyRange): Promise<number>;
|
|
37
|
+
put(doc: Schema['Doc'], key?: Schema['Key']): Promise<IDBValidKey>;
|
|
38
|
+
get(key: Schema['Key']): Promise<Schema["Doc"] | undefined>;
|
|
39
|
+
select(key?: Schema['Key'] | IDBKeyRange | null, count?: number): Promise<Schema["Doc"][]>;
|
|
40
|
+
drop(keys: Schema['Key'] | IDBKeyRange): Promise<undefined>;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare namespace $ {
|
|
45
|
+
type $mol_db_store_schema = {
|
|
46
|
+
Key: IDBValidKey;
|
|
47
|
+
Doc: unknown;
|
|
48
|
+
Indexes: Record<string, IDBValidKey[]>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare namespace $ {
|
|
53
|
+
function $mol_db<Schema extends $mol_db_schema>(this: $, name: string, ...migrations: ((transaction: $mol_db_transaction<$mol_db_schema>) => void)[]): Promise<$mol_db_database<Schema>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare namespace $ {
|
|
57
|
+
type $mol_db_schema = Record<string, $mol_db_store_schema>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare namespace $ {
|
|
61
|
+
class $mol_db_database<Schema extends $mol_db_schema> {
|
|
62
|
+
readonly native: IDBDatabase;
|
|
63
|
+
constructor(native: IDBDatabase);
|
|
64
|
+
get name(): string;
|
|
65
|
+
get version(): number;
|
|
66
|
+
get stores(): (keyof Schema)[];
|
|
67
|
+
read<Names extends Exclude<keyof Schema, symbol | number>>(...names: Names[]): { [Name in keyof Pick<Schema, Names>]: $mol_db_store<Pick<Schema, Names>[Name]>; };
|
|
68
|
+
change<Names extends Exclude<keyof Schema, symbol | number>>(...names: Names[]): $mol_db_transaction<Pick<Schema, Names>>;
|
|
69
|
+
kill(): Promise<void>;
|
|
70
|
+
destructor(): void;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface IDBTransaction {
|
|
75
|
+
commit(): void;
|
|
76
|
+
}
|
|
77
|
+
declare namespace $ {
|
|
78
|
+
class $mol_db_transaction<Schema extends $mol_db_schema> {
|
|
79
|
+
readonly native: IDBTransaction;
|
|
80
|
+
constructor(native: IDBTransaction);
|
|
81
|
+
get stores(): { [Name in keyof Schema]: $mol_db_store<Schema[Name]>; };
|
|
82
|
+
store_make(name: string): IDBObjectStore;
|
|
83
|
+
store_drop(name: string): this;
|
|
84
|
+
abort(): void;
|
|
85
|
+
commit(): Promise<void>;
|
|
86
|
+
get db(): $mol_db_database<$mol_db_schema>;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare namespace $ {
|
|
91
|
+
class $mol_db_index<Schema extends $mol_db_index_schema> {
|
|
92
|
+
readonly native: IDBIndex;
|
|
93
|
+
constructor(native: IDBIndex);
|
|
94
|
+
get name(): string;
|
|
95
|
+
get paths(): string[];
|
|
96
|
+
get unique(): boolean;
|
|
97
|
+
get multiple(): boolean;
|
|
98
|
+
get store(): $mol_db_store<$mol_db_store_schema>;
|
|
99
|
+
get transaction(): $mol_db_transaction<$mol_db_schema>;
|
|
100
|
+
get db(): $mol_db_database<$mol_db_schema>;
|
|
101
|
+
count(keys?: Schema['Key'] | IDBKeyRange): Promise<number>;
|
|
102
|
+
get(key: Schema['Key']): Promise<Schema["Doc"] | undefined>;
|
|
103
|
+
select(key?: Schema['Key'] | IDBKeyRange | null, count?: number): Promise<Schema["Doc"][]>;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare namespace $ {
|
|
108
|
+
type $mol_db_index_schema = {
|
|
109
|
+
Key: IDBValidKey[];
|
|
110
|
+
Doc: unknown;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export = $;
|
package/node.deps.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"files":["LICENSE","README.md","lang.lang.tree","mam.jam.js","mam.ts","package.json","sandbox.config.json","tsconfig.json","tsfmt.json","yarn.lock","mol/CNAME","mol/CODE_OF_CONDUCT.md","mol/CONTRIBUTING.md","mol/LICENSE","mol/index.html","mol/mol.meta.tree","mol/readme.md","mol/db/response/response.ts","mol/db/store/store.ts","mol/db/store/store_schema.ts","mol/db/README.md","mol/db/db.ts","mol/db/db_schema.ts","mol/db/database/database.ts","mol/db/transaction/transaction.ts","mol/db/index/index.ts","mol/db/index/index_schema.ts"],"mods":{},"deps_in":{"mol":{"mol/db":-9007199254740991},"":{"mol":-9007199254740991},"mol/db/transaction":{},"mol/db":{"mol/db/transaction":-1,"mol/db/database":-1},"mol/db/store":{"mol/db/transaction":-5,"mol/db/index":-3,"mol/db":-1},"mol/db/index":{},"mol/db/response":{"mol/db/index":-3,"mol/db/store":-3,"mol/db/database":-3,"mol/db":-2},"mol/db/database":{"mol/db/transaction":-3}},"deps_out":{"mol/db":{"mol":-9007199254740991,"mol/db/response":-2,"mol/db/store":-1},"mol":{"":-9007199254740991},"mol/db/transaction":{"mol/db":-1,"mol/db/store":-5,"mol/db/database":-3},"mol/db/store":{"mol/db/response":-3},"mol/db/index":{"mol/db/store":-3,"mol/db/response":-3},"mol/db/response":{},"mol/db/database":{"mol/db":-1,"mol/db/response":-3}},"sloc":{"LICENSE":113,"md":603,"tree":31,"js":10,"ts":283,"json":86,"lock":935,"CNAME":1,"html":1},"deps":{"mol/db":{"..":-9007199254740991,"/mol/db":-1,"/mol/db/schema":-1,"/mol/db/transaction":-2,"/mol/db/response":-2,"/mol/db/database":-2,"/mol/db/store/schema":-1},"mol":{"..":-9007199254740991},"":{},"mol/db/transaction":{"..":-9007199254740991,"/mol/db/transaction":-1,"/mol/db/schema":-1,"/mol/db/store":-5,"/mol/db/database":-3},"mol/db/store":{"..":-9007199254740991,"/mol/db/store":-1,"/mol/db/store/schema":-1,"/mol/db/index":-5,"/mol/db/transaction":-3,"/mol/db/response":-3},"mol/db/index":{"..":-9007199254740991,"/mol/db/index":-1,"/mol/db/index/schema":-1,"/mol/db/store":-3,"/mol/db/response":-3},"mol/db/response":{"..":-9007199254740991,"/mol/db/response":-1},"mol/db/database":{"..":-9007199254740991,"/mol/db/database":-1,"/mol/db/schema":-1,"/mol/db/transaction":-3,"/mol/db/response":-3}}}
|
package/node.esm.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var exports = void 0;
|
|
3
|
+
"use strict"
|
|
4
|
+
|
|
5
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
var globalThis = globalThis || ( typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this )
|
|
13
|
+
var $ = ( typeof module === 'object' ) ? Object.setPrototypeOf( module['export'+'s'] , globalThis ) : globalThis
|
|
14
|
+
$.$$ = $
|
|
15
|
+
|
|
16
|
+
;
|
|
17
|
+
|
|
18
|
+
var $node = $node || {}
|
|
19
|
+
void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../" ) ] };
|
|
20
|
+
;
|
|
21
|
+
"use strict";
|
|
22
|
+
Error.stackTraceLimit = 50;
|
|
23
|
+
var $;
|
|
24
|
+
(function ($) {
|
|
25
|
+
})($ || ($ = {}));
|
|
26
|
+
module.exports = $;
|
|
27
|
+
//mam.js.map
|
|
28
|
+
;
|
|
29
|
+
|
|
30
|
+
$node[ "../mam" ] = $node[ "../mam.js" ] = module.exports }.call( {} , {} )
|
|
31
|
+
;
|
|
32
|
+
"use strict";
|
|
33
|
+
var $;
|
|
34
|
+
(function ($) {
|
|
35
|
+
function $mol_db_response(request) {
|
|
36
|
+
return new Promise((done, fail) => {
|
|
37
|
+
request.onerror = () => fail(new Error(request.error.message));
|
|
38
|
+
request.onsuccess = () => done(request.result);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
$.$mol_db_response = $mol_db_response;
|
|
42
|
+
})($ || ($ = {}));
|
|
43
|
+
//response.js.map
|
|
44
|
+
;
|
|
45
|
+
"use strict";
|
|
46
|
+
var $;
|
|
47
|
+
(function ($) {
|
|
48
|
+
class $mol_db_store {
|
|
49
|
+
native;
|
|
50
|
+
constructor(native) {
|
|
51
|
+
this.native = native;
|
|
52
|
+
}
|
|
53
|
+
get name() {
|
|
54
|
+
return this.native.name;
|
|
55
|
+
}
|
|
56
|
+
get path() {
|
|
57
|
+
return this.native.keyPath;
|
|
58
|
+
}
|
|
59
|
+
get incremental() {
|
|
60
|
+
return this.native.autoIncrement;
|
|
61
|
+
}
|
|
62
|
+
get indexes() {
|
|
63
|
+
return new Proxy({}, {
|
|
64
|
+
ownKeys: () => [...this.native.indexNames],
|
|
65
|
+
has: (_, name) => this.native.indexNames.contains(name),
|
|
66
|
+
get: (_, name) => new $.$mol_db_index(this.native.index(name))
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
index_make(name, path = [], unique = false, multiEntry = false) {
|
|
70
|
+
return this.native.createIndex(name, path, { multiEntry, unique });
|
|
71
|
+
}
|
|
72
|
+
index_drop(name) {
|
|
73
|
+
this.native.deleteIndex(name);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
get transaction() {
|
|
77
|
+
return new $.$mol_db_transaction(this.native.transaction);
|
|
78
|
+
}
|
|
79
|
+
get db() {
|
|
80
|
+
return this.transaction.db;
|
|
81
|
+
}
|
|
82
|
+
clear() {
|
|
83
|
+
return $.$mol_db_response(this.native.clear());
|
|
84
|
+
}
|
|
85
|
+
count(keys) {
|
|
86
|
+
return $.$mol_db_response(this.native.count(keys));
|
|
87
|
+
}
|
|
88
|
+
put(doc, key) {
|
|
89
|
+
return $.$mol_db_response(this.native.put(doc, key));
|
|
90
|
+
}
|
|
91
|
+
get(key) {
|
|
92
|
+
return $.$mol_db_response(this.native.get(key));
|
|
93
|
+
}
|
|
94
|
+
select(key, count) {
|
|
95
|
+
return $.$mol_db_response(this.native.getAll(key, count));
|
|
96
|
+
}
|
|
97
|
+
drop(keys) {
|
|
98
|
+
return $.$mol_db_response(this.native.delete(keys));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
$.$mol_db_store = $mol_db_store;
|
|
102
|
+
})($ || ($ = {}));
|
|
103
|
+
//store.js.map
|
|
104
|
+
;
|
|
105
|
+
"use strict";
|
|
106
|
+
//store_schema.js.map
|
|
107
|
+
;
|
|
108
|
+
"use strict";
|
|
109
|
+
var $;
|
|
110
|
+
(function ($) {
|
|
111
|
+
async function $mol_db(name, ...migrations) {
|
|
112
|
+
const request = this.indexedDB.open(name, migrations.length ? migrations.length + 1 : undefined);
|
|
113
|
+
request.onupgradeneeded = event => {
|
|
114
|
+
migrations.splice(0, event.oldVersion - 1);
|
|
115
|
+
const transaction = new $.$mol_db_transaction(request.transaction);
|
|
116
|
+
for (const migrate of migrations)
|
|
117
|
+
migrate(transaction);
|
|
118
|
+
};
|
|
119
|
+
const db = await $.$mol_db_response(request);
|
|
120
|
+
return new $.$mol_db_database(db);
|
|
121
|
+
}
|
|
122
|
+
$.$mol_db = $mol_db;
|
|
123
|
+
})($ || ($ = {}));
|
|
124
|
+
//db.js.map
|
|
125
|
+
;
|
|
126
|
+
"use strict";
|
|
127
|
+
//db_schema.js.map
|
|
128
|
+
;
|
|
129
|
+
"use strict";
|
|
130
|
+
var $;
|
|
131
|
+
(function ($) {
|
|
132
|
+
class $mol_db_database {
|
|
133
|
+
native;
|
|
134
|
+
constructor(native) {
|
|
135
|
+
this.native = native;
|
|
136
|
+
}
|
|
137
|
+
get name() {
|
|
138
|
+
return this.native.name;
|
|
139
|
+
}
|
|
140
|
+
get version() {
|
|
141
|
+
return this.native.version;
|
|
142
|
+
}
|
|
143
|
+
get stores() {
|
|
144
|
+
return [...this.native.objectStoreNames];
|
|
145
|
+
}
|
|
146
|
+
read(...names) {
|
|
147
|
+
return new $.$mol_db_transaction(this.native.transaction(names, 'readonly')).stores;
|
|
148
|
+
}
|
|
149
|
+
change(...names) {
|
|
150
|
+
return new $.$mol_db_transaction(this.native.transaction(names, 'readwrite'));
|
|
151
|
+
}
|
|
152
|
+
kill() {
|
|
153
|
+
this.native.close();
|
|
154
|
+
const request = indexedDB.deleteDatabase(this.name);
|
|
155
|
+
request.onblocked = console.error;
|
|
156
|
+
return $.$mol_db_response(request).then(() => { });
|
|
157
|
+
}
|
|
158
|
+
destructor() {
|
|
159
|
+
this.native.close();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
$.$mol_db_database = $mol_db_database;
|
|
163
|
+
})($ || ($ = {}));
|
|
164
|
+
//database.js.map
|
|
165
|
+
;
|
|
166
|
+
"use strict";
|
|
167
|
+
var $;
|
|
168
|
+
(function ($) {
|
|
169
|
+
class $mol_db_transaction {
|
|
170
|
+
native;
|
|
171
|
+
constructor(native) {
|
|
172
|
+
this.native = native;
|
|
173
|
+
}
|
|
174
|
+
get stores() {
|
|
175
|
+
return new Proxy({}, {
|
|
176
|
+
ownKeys: () => [...this.native.objectStoreNames],
|
|
177
|
+
has: (_, name) => this.native.objectStoreNames.contains(name),
|
|
178
|
+
get: (_, name) => new $.$mol_db_store(this.native.objectStore(name)),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
store_make(name) {
|
|
182
|
+
return this.native.db.createObjectStore(name, { autoIncrement: true });
|
|
183
|
+
}
|
|
184
|
+
store_drop(name) {
|
|
185
|
+
this.native.db.deleteObjectStore(name);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
abort() {
|
|
189
|
+
this.native.abort();
|
|
190
|
+
}
|
|
191
|
+
commit() {
|
|
192
|
+
this.native.commit();
|
|
193
|
+
return new Promise((done, fail) => {
|
|
194
|
+
this.native.onerror = () => fail(new Error(this.native.error.message));
|
|
195
|
+
this.native.oncomplete = () => done();
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
get db() {
|
|
199
|
+
return new $.$mol_db_database(this.native.db);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
$.$mol_db_transaction = $mol_db_transaction;
|
|
203
|
+
})($ || ($ = {}));
|
|
204
|
+
//transaction.js.map
|
|
205
|
+
;
|
|
206
|
+
"use strict";
|
|
207
|
+
var $;
|
|
208
|
+
(function ($) {
|
|
209
|
+
class $mol_db_index {
|
|
210
|
+
native;
|
|
211
|
+
constructor(native) {
|
|
212
|
+
this.native = native;
|
|
213
|
+
}
|
|
214
|
+
get name() {
|
|
215
|
+
return this.native.name;
|
|
216
|
+
}
|
|
217
|
+
get paths() {
|
|
218
|
+
return this.native.keyPath;
|
|
219
|
+
}
|
|
220
|
+
get unique() {
|
|
221
|
+
return this.native.unique;
|
|
222
|
+
}
|
|
223
|
+
get multiple() {
|
|
224
|
+
return this.native.multiEntry;
|
|
225
|
+
}
|
|
226
|
+
get store() {
|
|
227
|
+
return new $.$mol_db_store(this.native.objectStore);
|
|
228
|
+
}
|
|
229
|
+
get transaction() {
|
|
230
|
+
return this.store.transaction;
|
|
231
|
+
}
|
|
232
|
+
get db() {
|
|
233
|
+
return this.store.db;
|
|
234
|
+
}
|
|
235
|
+
count(keys) {
|
|
236
|
+
return $.$mol_db_response(this.native.count(keys));
|
|
237
|
+
}
|
|
238
|
+
get(key) {
|
|
239
|
+
return $.$mol_db_response(this.native.get(key));
|
|
240
|
+
}
|
|
241
|
+
select(key, count) {
|
|
242
|
+
return $.$mol_db_response(this.native.getAll(key, count));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
$.$mol_db_index = $mol_db_index;
|
|
246
|
+
})($ || ($ = {}));
|
|
247
|
+
//index.js.map
|
|
248
|
+
;
|
|
249
|
+
"use strict";
|
|
250
|
+
//index_schema.js.map
|
|
251
|
+
;
|
|
252
|
+
export default $
|
|
253
|
+
//# sourceMappingURL=node.esm.js.map
|
package/node.esm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../mam.jam.js","-","../../../mam.ts","../response/response.ts","../store/store.ts","../store/store_schema.js","../db.ts","../db_schema.js","../database/database.ts","../transaction/transaction.ts","../index/index.ts","../index/index_schema.js"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACbA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;AAMX,CAAC,EANS,CAAC,KAAD,CAAC,QAMV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADblB;AACA;AACA;;AEFA,IAAU,CAAC,CAcV;AAdD,WAAU,CAAC;IAGV,SAAgB,gBAAgB,CAC/B,OAA6B;QAG7B,OAAO,IAAI,OAAO,CAAY,CAAE,IAAI,EAAE,IAAI,EAAE,EAAE;YAC7C,OAAO,CAAC,OA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tB,CAAC;QAEL,IAAI,IAAI;YACP,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;QACxB,CAAC;QAED,IAAI,KAAK;YACR,OAAO,IAAI,CAAC,MAAM,CAAC,OAAmB,CAAA;QACvC,CAAC;QAED,IAAI,MAAM;YACT,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;QAC1B,CAAC;QAED,IAAI,QAAQ;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;QAC9B,CAAC;QAED,IAAI,KAAK;YACR,OAAO,IAAI,EAAA,aAAa,CACvB,IAAI,CAAC,MAAM,CAAC,WAAW,CACvB,CAAA;QACF,CAAC;QAED,IAAI,WAAW;YACd,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAA;QAC9B,CAAC;QAED,IAAI,EAAE;YACL,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;QACrB,CAAC;QAGD,KAAK,CAAE,IAAkC;YACxC,OAAO,EAAA,gBAAgB,CAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAE,IAAI,CAAE,CAAE,CAAA;QACrD,CAAC;QAGD,GAAG,CAAE,GAAkB;YACtB,OAAO,EAAA,gBAAgB,CAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAE,GAAG,CAA6C,CAAE,CAAA;QAC7F,CAAC;QAGD,MAAM,CAAE,GAAwC,EAAE,KAAc;YAC/D,OAAO,EAAA,gBAAgB,CAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAE,GAAG,EAAE,KAAK,CAAmC,CAAE,CAAA;QAC7F,CAAC;KAED;IAnDY,eAAa,gBAmDzB,CAAA;AAEF,CAAC,EAxDS,CAAC,KAAD,CAAC,QAwDV;;;ACxDD;AACA;AACA;AVFA","file":"node.esm.js","sourcesContent":[null,null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\t\n\t/** Converts IDBResult to Promise */\n\texport function $mol_db_response< Result >(\n\t\trequest: IDBRequest< Result >\n\t) {\n\t\t\n\t\treturn new Promise< Result >( ( done, fail )=> {\n\t\t\trequest.onerror = ()=> fail( new Error( request.error!.message ) )\n\t\t\trequest.onsuccess = ()=> done( request.result )\n\t\t} )\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\t/** IndexedDB ObjectStore wrapper. */\n\texport class $mol_db_store< Schema extends $mol_db_store_schema > {\n\t\t\n\t\tconstructor(\n\t\t\treadonly native: IDBObjectStore,\n\t\t) {}\n\t\t\n\t\tget name() {\n\t\t\treturn this.native.name\n\t\t}\n\t\t\n\t\tget path() {\n\t\t\treturn this.native.keyPath\n\t\t}\n\t\t\n\t\tget incremental() {\n\t\t\treturn this.native.autoIncrement\n\t\t}\n\t\t\n\t\t/** Returns dictionary of all existen Indexes. */\n\t\tget indexes() {\n\t\t\treturn new Proxy(\n\t\t\t\t{} as {\n\t\t\t\t\t[ Name in keyof Schema['Indexes'] ]: $mol_db_index<{\n\t\t\t\t\t\tKey: Schema['Indexes'][ Name ],\n\t\t\t\t\t\tDoc: Schema['Doc'],\n\t\t\t\t\t}>\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\townKeys: ()=> [ ... this.native.indexNames ],\n\t\t\t\t\thas: ( _, name: string )=> this.native.indexNames.contains( name ),\n\t\t\t\t\tget: ( _, name: string )=> new $mol_db_index( this.native.index( name ) )\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\t\n\t\t/** Creates new Index */\n\t\tindex_make(\n\t\t\tname: string,\n\t\t\tpath = [] as string[],\n\t\t\tunique = false,\n\t\t\tmultiEntry = false,\n\t\t) {\n\t\t\treturn this.native.createIndex( name, path, { multiEntry, unique } )\n\t\t}\n\t\t\n\t\t/** Drops existen Index */\n\t\tindex_drop( name: string ) {\n\t\t\tthis.native.deleteIndex( name )\n\t\t\treturn this\n\t\t}\n\t\t\n\t\tget transaction() {\n\t\t\treturn new $mol_db_transaction(\n\t\t\t\tthis.native.transaction\n\t\t\t)\n\t\t}\n\t\t\n\t\tget db() {\n\t\t\treturn this.transaction.db\n\t\t}\n\t\t\n\t\t/** Deletes all stored Documents */\n\t\tclear() {\n\t\t\treturn $mol_db_response( this.native.clear() )\n\t\t}\n\t\t\n\t\t/** Counts Documents by primary key(s) */\n\t\tcount( keys?: Schema['Key'] | IDBKeyRange ) {\n\t\t\treturn $mol_db_response( this.native.count( keys ) )\n\t\t}\n\t\t\n\t\t/** Stores single Document by primary key. */\n\t\tput( doc: Schema['Doc'], key?: Schema['Key'] ) {\n\t\t\treturn $mol_db_response( this.native.put( doc, key ) )\n\t\t}\n\t\t\n\t\t/** Returns Document by primary key. */\n\t\tget( key: Schema['Key'] ) {\n\t\t\treturn $mol_db_response( this.native.get( key ) as IDBRequest< Schema['Doc'] | undefined > )\n\t\t}\n\t\t\n\t\t/** Selects Documents by primary keys. */\n\t\tselect( key?: Schema['Key'] | IDBKeyRange | null, count?: number ) {\n\t\t\treturn $mol_db_response( this.native.getAll( key, count ) as IDBRequest< Schema['Doc'][] > )\n\t\t}\n\t\t\n\t\t/** Deletes Documents by primary key(s). */\n\t\tdrop( keys: Schema['Key'] | IDBKeyRange ) {\n\t\t\treturn $mol_db_response( this.native.delete( keys ) )\n\t\t}\n\t\t\n\t}\n\t\n}\n",null,"namespace $ {\n\t\n\t/**\n\t * Creates new or returns existen database with automatic schema migration.\n\t * Schema version is based on migrations count.\n\t * Migrations code mustn't be changed after deploy.\n\t * Only adding migrations at the end is allowed.\n\t * Only new migrations will be applyed to existen DB.\n\t * Schema changes allowed only through migratios. \n\t */\n\texport async function $mol_db< Schema extends $mol_db_schema >(\n\t\tthis: $,\n\t\tname: string,\n\t\t... migrations: ( ( transaction: $mol_db_transaction< $mol_db_schema > )=> void )[]\n\t) {\n\t\t\n\t\tconst request = this.indexedDB.open( name, migrations.length ? migrations.length + 1 : undefined )\n\t\t\n\t\trequest.onupgradeneeded = event => {\n\t\t\t\n\t\t\tmigrations.splice( 0, event.oldVersion - 1 )\n\t\t\tconst transaction = new $mol_db_transaction( request.transaction! )\n\t\t\t\n\t\t\tfor( const migrate of migrations ) migrate( transaction )\n\t\t\t\n\t\t}\n\t\t\n\t\tconst db = await $mol_db_response( request )\n\t\t\n\t\treturn new $mol_db_database< Schema >( db )\n\t}\n\t\n}\n",null,"namespace $ {\n\t\n\t/** IndexedDB instance wrapper. */\n\texport class $mol_db_database< Schema extends $mol_db_schema > {\n\t\t\n\t\tconstructor(\n\t\t\treadonly native: IDBDatabase,\n\t\t) { }\n\t\t\n\t\t/** Returns database name. */\n\t\tget name() {\n\t\t\treturn this.native.name\n\t\t}\n\t\t\n\t\t/** Returns database schema version. */\n\t\tget version() {\n\t\t\treturn this.native.version\n\t\t}\n\t\t\n\t\t/** Returns all stores names. */\n\t\tget stores() {\n\t\t\treturn [ ... this.native.objectStoreNames ] as ( keyof Schema )[]\n\t\t}\n\t\t\n\t\t/** Create read-only transaction. */\n\t\tread< Names extends Exclude< keyof Schema, symbol | number > >( ... names: Names[] ) {\n\t\t\treturn new $mol_db_transaction< Pick< Schema, Names > >(\n\t\t\t\tthis.native.transaction( names, 'readonly' )\n\t\t\t).stores\n\t\t}\n\t\t\n\t\t/** Create read/write transaction. */\n\t\tchange< Names extends Exclude< keyof Schema, symbol | number > >( ... names: Names[] ) {\n\t\t\treturn new $mol_db_transaction< Pick< Schema, Names > >(\n\t\t\t\tthis.native.transaction( names, 'readwrite' )\n\t\t\t)\n\t\t}\n\t\t\n\t\t/**\n\t\t * Deletes database.\n\t\t * DB can be deleted only after end of all transactions.\n\t\t */\n\t\tkill() {\n\t\t\t\n\t\t\tthis.native.close()\n\t\t\t\n\t\t\tconst request = indexedDB.deleteDatabase( this.name )\n\t\t\t\n\t\t\trequest.onblocked = console.error\n\t\t\treturn $mol_db_response( request ).then( ()=> {} )\n\t\t\t\n\t\t}\n\t\t\n\t\t/**\n\t\t * Closes DB connection.\n\t\t * Connection really be closed only after end of all transactions.\n\t\t */\n\t\tdestructor() {\n\t\t\tthis.native.close()\n\t\t}\n\t\t\n\t}\n\t\n}\n","interface IDBTransaction {\n\tcommit(): void\n}\n\nnamespace $ {\n\t\n\t/** IndexedDB Transaction wrapper. */\n\texport class $mol_db_transaction< Schema extends $mol_db_schema > {\n\t\t\n\t\tconstructor(\n\t\t\treadonly native: IDBTransaction,\n\t\t) {}\n\t\t\n\t\t/** Returns dictionary of all existen Stores. */\n\t\tget stores() {\n\t\t\treturn new Proxy(\n\t\t\t\t{} as {\n\t\t\t\t\t[ Name in keyof Schema ]: $mol_db_store< Schema[ Name ] >\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\townKeys: ()=> [ ... this.native.objectStoreNames ],\n\t\t\t\t\thas: ( _, name: string )=> this.native.objectStoreNames.contains( name ),\n\t\t\t\t\tget: ( _, name: string )=> new $mol_db_store( this.native.objectStore( name ) ),\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\t\n\t\t/** Creates new Store */\n\t\tstore_make( name: string ) {\n\t\t\treturn this.native.db.createObjectStore( name, { autoIncrement: true } )\n\t\t}\n\t\t\n\t\t/** Drops existen Store */\n\t\tstore_drop( name: string ) {\n\t\t\tthis.native.db.deleteObjectStore( name )\n\t\t\treturn this\n\t\t}\n\t\t\n\t\t/** Instant abort transaction. Any errors aborts transactions automatically. */\n\t\tabort() {\n\t\t\tthis.native.abort()\n\t\t}\n\t\t\n\t\t/** Instant commits transaction. Without errors commit proceed automatically later. */\n\t\tcommit() {\n\t\t\t\n\t\t\tthis.native.commit()\n\t\t\t\n\t\t\treturn new Promise< void >( ( done, fail )=> {\n\t\t\t\tthis.native.onerror = ()=> fail( new Error( this.native.error!.message ) )\n\t\t\t\tthis.native.oncomplete = ()=> done()\n\t\t\t} )\n\t\t\t\n\t\t}\n\t\t\n\t\tget db() {\n\t\t\treturn new $mol_db_database(\n\t\t\t\tthis.native.db\n\t\t\t)\n\t\t}\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\t/** IndexedDB Index wrapper. */\n\texport class $mol_db_index< Schema extends $mol_db_index_schema > {\n\t\t\n\t\tconstructor(\n\t\t\treadonly native: IDBIndex,\n\t\t) { }\n\t\t\n\t\tget name() {\n\t\t\treturn this.native.name\n\t\t}\n\t\t\n\t\tget paths() {\n\t\t\treturn this.native.keyPath as string[]\n\t\t}\n\t\t\n\t\tget unique() {\n\t\t\treturn this.native.unique\n\t\t}\n\t\t\n\t\tget multiple() {\n\t\t\treturn this.native.multiEntry\n\t\t}\n\t\t\n\t\tget store() {\n\t\t\treturn new $mol_db_store(\n\t\t\t\tthis.native.objectStore\n\t\t\t)\n\t\t}\n\t\t\n\t\tget transaction() {\n\t\t\treturn this.store.transaction\n\t\t}\n\t\t\n\t\tget db() {\n\t\t\treturn this.store.db\n\t\t}\n\t\t\n\t\t/** Counts Documents by key(s) */\n\t\tcount( keys?: Schema['Key'] | IDBKeyRange ) {\n\t\t\treturn $mol_db_response( this.native.count( keys ) )\n\t\t}\n\t\t\n\t\t/** Returns Document by primary key. */\n\t\tget( key: Schema['Key'] ) {\n\t\t\treturn $mol_db_response( this.native.get( key ) as IDBRequest< Schema['Doc'] | undefined > )\n\t\t}\n\t\t\n\t\t/** Selects Documents by primary keys. */\n\t\tselect( key?: Schema['Key'] | IDBKeyRange | null, count?: number ) {\n\t\t\treturn $mol_db_response( this.native.getAll( key, count ) as IDBRequest< Schema['Doc'][] > )\n\t\t}\n\t\t\n\t}\n\t\n}\n",null]}
|