@buley/dash 0.0.30 → 2.1.1
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/README.md +82 -65
- package/dist/src/engine/ai.d.ts +10 -0
- package/dist/src/engine/ai.js +46 -0
- package/dist/src/engine/sqlite.d.ts +31 -0
- package/dist/src/engine/sqlite.js +255 -0
- package/dist/src/engine/vec_extension.d.ts +5 -0
- package/dist/src/engine/vec_extension.js +10 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/mcp/server.d.ts +8 -0
- package/dist/src/mcp/server.js +87 -0
- package/dist/src/reactivity/signal.d.ts +3 -0
- package/dist/src/reactivity/signal.js +31 -0
- package/dist/src/sync/backup.d.ts +12 -0
- package/dist/src/sync/backup.js +44 -0
- package/dist/src/sync/connection.d.ts +16 -0
- package/dist/src/sync/connection.js +29 -0
- package/dist/src/sync/provider.d.ts +11 -0
- package/dist/src/sync/provider.js +67 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +33 -31
- package/.coveralls.yml +0 -1
- package/.github/workflows/opencommit.yml +0 -33
- package/.github/workflows/testing.yml +0 -20
- package/.gitmodules +0 -0
- package/behaviors/cache.dev.js +0 -282
- package/behaviors/changes.dev.js +0 -337
- package/behaviors/collect.dev.js +0 -40
- package/behaviors/examples/async.dev.js +0 -17
- package/behaviors/firebase.dev.js +0 -283
- package/behaviors/live.dev.js +0 -67
- package/behaviors/map.dev.js +0 -54
- package/behaviors/mapreduce.dev.js +0 -68
- package/behaviors/match.dev.js +0 -66
- package/behaviors/patch.dev.js +0 -69
- package/behaviors/rest.dev.js +0 -340
- package/behaviors/shorthand.dev.js +0 -59
- package/behaviors/stats.dev.js +0 -672
- package/dist/behaviors/index.js +0 -142
- package/dist/database/index.js +0 -76
- package/dist/databases/index.js +0 -121
- package/dist/entry/index.js +0 -166
- package/dist/index.js +0 -93
- package/dist/indexes/index.js +0 -153
- package/dist/store/index.js +0 -97
- package/dist/stores/index.js +0 -90
- package/dist/utilities/index.js +0 -174
- package/documentation/database/closing.md +0 -3
- package/documentation/database/getting.md +0 -1
- package/documentation/database/opening.md +0 -5
- package/documentation/database/removing.md +0 -3
- package/documentation/databases.md +0 -21
- package/documentation/entries.md +0 -13
- package/documentation/entry/adding.md +0 -1
- package/documentation/entry/getting.md +0 -4
- package/documentation/entry/putting.md +0 -0
- package/documentation/entry/removing.md +0 -3
- package/documentation/entry/updating.md +0 -0
- package/documentation/general/security.md +0 -10
- package/documentation/general/transaction/requests.md +0 -3
- package/documentation/general/transactions.md +0 -5
- package/documentation/index/creating.md +0 -1
- package/documentation/index/getting.md +0 -1
- package/documentation/index/iterating.md +0 -1
- package/documentation/index/removing.md +0 -1
- package/documentation/indexes.md +0 -3
- package/documentation/key/cursors.md +0 -5
- package/documentation/key/range/bounds.md +0 -11
- package/documentation/key/range/direction.md +0 -1
- package/documentation/key/ranges.md +0 -3
- package/documentation/keys.md +0 -12
- package/documentation/objectstore/clearing.md +0 -1
- package/documentation/objectstore/creating.md +0 -1
- package/documentation/objectstore/getting.md +0 -1
- package/documentation/objectstore/iteration.md +0 -1
- package/documentation/objectstore/removing.md +0 -1
- package/documentation/overview.md +0 -5
- package/documentation/stores.md +0 -13
- package/jest.config.js +0 -12
- package/src/behaviors/index.ts +0 -140
- package/src/database/index.ts +0 -81
- package/src/databases/index.ts +0 -127
- package/src/entry/index.ts +0 -183
- package/src/index/index.ts +0 -61
- package/src/index.ts +0 -96
- package/src/indexes/index.ts +0 -151
- package/src/store/index.ts +0 -102
- package/src/stores/index.ts +0 -90
- package/src/utilities/index.ts +0 -349
- package/tests/behaviors/behaviors.spec.ts +0 -123
- package/tests/database/database.spec.ts +0 -177
- package/tests/databases/databases.spec.ts +0 -199
- package/tests/entry/entry.spec.ts +0 -252
- package/tests/index/index.spec.ts +0 -94
- package/tests/indexes/indexes.spec.ts +0 -203
- package/tests/store/store.spec.ts +0 -164
- package/tests/stores/stores.spec.ts +0 -148
- package/tests/utilities/clone.spec.ts +0 -48
- package/tests/utilities/cloneError.spec.ts +0 -33
- package/tests/utilities/contains.spec.ts +0 -28
- package/tests/utilities/exists.spec.ts +0 -21
- package/tests/utilities/is.spec.ts +0 -37
- package/tests/utilities/isArray.spec.ts +0 -21
- package/tests/utilities/isBoolean.spec.ts +0 -23
- package/tests/utilities/isEmpty.spec.ts +0 -45
- package/tests/utilities/isFunction.spec.ts +0 -30
- package/tests/utilities/isNumber.spec.ts +0 -29
- package/tests/utilities/isObject.spec.ts +0 -42
- package/tests/utilities/isRegEx.spec.ts +0 -33
- package/tests/utilities/isString.spec.ts +0 -25
- package/tests/utilities/isnt.spec.ts +0 -50
- package/tests/utilities/randomId.spec.ts +0 -39
- package/tests/utilities/safeApply.spec.ts +0 -49
- package/tests/utilities/safeEach.spec.ts +0 -38
- package/tests/utilities/safeIterate.spec.ts +0 -47
- package/tsconfig.json +0 -16
package/src/index/index.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Index methods
|
|
3
|
-
* @module index
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { cloneError, DashContext } from "../utilities";
|
|
7
|
-
|
|
8
|
-
// Index methods
|
|
9
|
-
export const indexMethods = {
|
|
10
|
-
/**
|
|
11
|
-
* Get an index.
|
|
12
|
-
* @param get_ctx
|
|
13
|
-
* @returns Promise<DashContext>
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
get: (get_ctx: DashContext) => {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
const request = get_ctx.idx?.get(get_ctx.key);
|
|
19
|
-
|
|
20
|
-
request?.addEventListener('success', () => {
|
|
21
|
-
get_ctx.entry = request.result;
|
|
22
|
-
resolve(get_ctx);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
request?.addEventListener('error', (event) => {
|
|
26
|
-
get_ctx.error = cloneError((event as any).target.error);
|
|
27
|
-
reject(get_ctx);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
/**
|
|
32
|
-
* Remove an index.
|
|
33
|
-
* @param remove_ctx
|
|
34
|
-
* @returns Promise<DashContext>
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
remove: (remove_ctx: DashContext) => {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
remove_ctx.objectstore?.deleteIndex(remove_ctx.key);
|
|
40
|
-
// Why don't we have success/error handlers?
|
|
41
|
-
// Because this method returns void, not a request object.
|
|
42
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/deleteIndex#return_value
|
|
43
|
-
resolve(remove_ctx);
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
/**
|
|
47
|
-
* Get indexes.
|
|
48
|
-
* @param ctx
|
|
49
|
-
* @returns Promise<DashContext>
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
getIndexes: (ctx: DashContext) => {
|
|
53
|
-
return new Promise((resolve) => {
|
|
54
|
-
const indexes = ctx.objectstore?.indexNames;
|
|
55
|
-
ctx.indexes = Array.from(indexes || []);
|
|
56
|
-
resolve(ctx);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export default indexMethods;
|
package/src/index.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
▀██ ▀██
|
|
3
|
-
▄▄ ██ ▄▄▄▄ ▄▄▄▄ ██ ▄▄
|
|
4
|
-
▄▀ ▀██ ▀▀ ▄██ ██▄ ▀ ██▀ ██
|
|
5
|
-
█▄ ██ ▄█▀ ██ ▄ ▀█▄▄ ██ ██
|
|
6
|
-
▀█▄▄▀██▄ ▀█▄▄▀█▀ █▀▄▄█▀ ▄██▄ ██▄
|
|
7
|
-
|
|
8
|
-
Dash is a simple, lightweight wrapper around the IndexedDB API.
|
|
9
|
-
There are four main modules: database, store, index, and entry.
|
|
10
|
-
Each module has a get, put, and remove method.
|
|
11
|
-
The library is designed to be used in a promise chain.
|
|
12
|
-
|
|
13
|
-
Version -> 0.0.1
|
|
14
|
-
Repo -> http://github.com/buley/dash
|
|
15
|
-
Author -> Taylor Buley (@taylorbuley)
|
|
16
|
-
Copyright -> (c) 2011-2024 Taylor Buley
|
|
17
|
-
License -> MIT (https://opensource.org/licenses/MIT)
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// Databases
|
|
21
|
-
import databaseMethods from './database';
|
|
22
|
-
import databasesMethods from './databases';
|
|
23
|
-
// Stores
|
|
24
|
-
import storeMethods from './store';
|
|
25
|
-
import storesMethods from './stores';
|
|
26
|
-
// Entries
|
|
27
|
-
import entryMethods from './entry';
|
|
28
|
-
// Indexes
|
|
29
|
-
import indexMethods from './index';
|
|
30
|
-
import indexesMethods from './indexes';
|
|
31
|
-
// Behaviors
|
|
32
|
-
import behaviorMethods from './behaviors';
|
|
33
|
-
|
|
34
|
-
const dash = ((internal: any) => {
|
|
35
|
-
'use strict';
|
|
36
|
-
|
|
37
|
-
var Public: any = {};
|
|
38
|
-
var names: string[] = [];
|
|
39
|
-
var name: string;
|
|
40
|
-
|
|
41
|
-
// Function to safely iterate over internal API and build the Public API
|
|
42
|
-
function safeIterate(obj: any, callback: (sig: string, fnref: Function) => void) {
|
|
43
|
-
for (const key in obj) {
|
|
44
|
-
if (obj.hasOwnProperty(key)) {
|
|
45
|
-
callback(key, obj[key]);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Function to wrap each request (assuming wrapRequest provides promise handling or similar)
|
|
51
|
-
function wrapRequest(fnref: Function, sig: string) {
|
|
52
|
-
return (...args: any[]) => {
|
|
53
|
-
try {
|
|
54
|
-
return fnref.apply(null, args);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error(`Error in ${sig}:`, error);
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Iterate over the internal API object and construct the Public API
|
|
63
|
-
safeIterate(internal, function (sig: string, fnref: Function) {
|
|
64
|
-
names = sig.split('.');
|
|
65
|
-
name = names[0];
|
|
66
|
-
Public[name] = Public[name] || {};
|
|
67
|
-
Public[name][names[1]] = wrapRequest(fnref, sig);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return Public;
|
|
71
|
-
})({
|
|
72
|
-
'add.entry': entryMethods.put,
|
|
73
|
-
'add.behavior': behaviorMethods.add,
|
|
74
|
-
'clear.store': storeMethods.clear,
|
|
75
|
-
'count.entries': entryMethods.count,
|
|
76
|
-
'get.behaviors': behaviorMethods.get,
|
|
77
|
-
'get.database': databaseMethods.get,
|
|
78
|
-
'get.databases': databasesMethods.get,
|
|
79
|
-
'get.store': storeMethods.get,
|
|
80
|
-
'get.stores': storesMethods.get,
|
|
81
|
-
//'get.index': indexMethods.get,
|
|
82
|
-
'get.indexes': indexesMethods.get,
|
|
83
|
-
'get.entries': entryMethods.get,
|
|
84
|
-
'get.entry': entryMethods.get,
|
|
85
|
-
'remove.database': databaseMethods.remove,
|
|
86
|
-
'remove.entries': entryMethods.remove,
|
|
87
|
-
//'remove.index': indexMethods.remove,
|
|
88
|
-
'remove.entry': entryMethods.remove,
|
|
89
|
-
'remove.store': storeMethods.remove,
|
|
90
|
-
'update.entries': entryMethods.update,
|
|
91
|
-
'update.entry': entryMethods.put,
|
|
92
|
-
'$$': behaviorMethods.process
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Export the dash library
|
|
96
|
-
export default dash;
|
package/src/indexes/index.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Indexes methods
|
|
4
|
-
* @module indexes
|
|
5
|
-
*/
|
|
6
|
-
import { cloneError, DashContext, safeApply } from "../utilities";
|
|
7
|
-
|
|
8
|
-
// Indexes methods
|
|
9
|
-
export const indexesMethods = {
|
|
10
|
-
/**
|
|
11
|
-
* Get all indexes from a specific object store.
|
|
12
|
-
* @param get_ctx The context object.
|
|
13
|
-
* @returns Promise<DashContext>
|
|
14
|
-
*/
|
|
15
|
-
get: function (get_ctx: DashContext): Promise<DashContext> {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
try {
|
|
18
|
-
get_ctx.indexes = get_ctx.objectstore?.indexNames;
|
|
19
|
-
if (get_ctx.on_success) {
|
|
20
|
-
safeApply(get_ctx.on_success, [get_ctx]);
|
|
21
|
-
}
|
|
22
|
-
resolve(get_ctx);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
get_ctx.error = cloneError(error as Error);
|
|
25
|
-
if (get_ctx.on_error) {
|
|
26
|
-
safeApply(get_ctx.on_error, [get_ctx]);
|
|
27
|
-
}
|
|
28
|
-
reject(get_ctx);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Add a new index to an object store.
|
|
35
|
-
* @param add_ctx The context object.
|
|
36
|
-
* @returns Promise<DashContext>
|
|
37
|
-
*/
|
|
38
|
-
add: function (add_ctx: DashContext): Promise<DashContext> {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
try {
|
|
41
|
-
add_ctx.objectstore?.createIndex(add_ctx.index, add_ctx.index_key_path, {
|
|
42
|
-
unique: !!add_ctx.index_unique,
|
|
43
|
-
multiEntry: !!add_ctx.index_multi_entry
|
|
44
|
-
});
|
|
45
|
-
if (add_ctx.on_success) {
|
|
46
|
-
safeApply(add_ctx.on_success, [add_ctx]);
|
|
47
|
-
}
|
|
48
|
-
resolve(add_ctx);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
add_ctx.error = cloneError(error as Error);
|
|
51
|
-
if (add_ctx.on_error) {
|
|
52
|
-
safeApply(add_ctx.on_error, [add_ctx]);
|
|
53
|
-
}
|
|
54
|
-
reject(add_ctx);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Remove an index from an object store.
|
|
61
|
-
* @param remove_ctx The context object.
|
|
62
|
-
* @returns Promise<DashContext>
|
|
63
|
-
*/
|
|
64
|
-
remove: function (remove_ctx: DashContext): Promise<DashContext> {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
try {
|
|
67
|
-
remove_ctx.objectstore?.deleteIndex(remove_ctx.index);
|
|
68
|
-
if (remove_ctx.on_success) {
|
|
69
|
-
safeApply(remove_ctx.on_success, [remove_ctx]);
|
|
70
|
-
}
|
|
71
|
-
resolve(remove_ctx);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
remove_ctx.error = cloneError(error as Error);
|
|
74
|
-
if (remove_ctx.on_error) {
|
|
75
|
-
safeApply(remove_ctx.on_error, [remove_ctx]);
|
|
76
|
-
}
|
|
77
|
-
reject(remove_ctx);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
/**
|
|
82
|
-
* Get all entries from a specific index.
|
|
83
|
-
* @param get_ctx The context object.
|
|
84
|
-
* @returns Promise<DashContext>
|
|
85
|
-
*/
|
|
86
|
-
getEntries: function (get_ctx: DashContext): Promise<DashContext> {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const request = get_ctx.objectstore?.index(get_ctx.index)?.openCursor();
|
|
89
|
-
|
|
90
|
-
if (!request) {
|
|
91
|
-
get_ctx.error = new Error("Failed to open cursor");
|
|
92
|
-
if (get_ctx.on_error) {
|
|
93
|
-
safeApply(get_ctx.on_error, [get_ctx]);
|
|
94
|
-
}
|
|
95
|
-
reject(get_ctx);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
request.onsuccess = function (event) {
|
|
100
|
-
const cursor = request.result;
|
|
101
|
-
if (cursor) {
|
|
102
|
-
if (get_ctx.on_success) {
|
|
103
|
-
safeApply(get_ctx.on_success, [cursor.value]);
|
|
104
|
-
}
|
|
105
|
-
cursor.continue();
|
|
106
|
-
} else {
|
|
107
|
-
if (get_ctx.on_complete) {
|
|
108
|
-
safeApply(get_ctx.on_complete, [get_ctx]);
|
|
109
|
-
}
|
|
110
|
-
resolve(get_ctx);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
request.onerror = function (event) {
|
|
115
|
-
get_ctx.error = cloneError(request.error!);
|
|
116
|
-
if (get_ctx.on_error) {
|
|
117
|
-
safeApply(get_ctx.on_error, [get_ctx]);
|
|
118
|
-
}
|
|
119
|
-
reject(get_ctx);
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
/**
|
|
124
|
-
* Counts the number of entries in a specific index.
|
|
125
|
-
* @param count_ctx The context object.
|
|
126
|
-
* @returns Promise<DashContext>
|
|
127
|
-
*/
|
|
128
|
-
countEntries: function (count_ctx: DashContext): Promise<DashContext> {
|
|
129
|
-
return new Promise((resolve, reject) => {
|
|
130
|
-
const request = count_ctx.objectstore?.index(count_ctx.index)?.count();
|
|
131
|
-
|
|
132
|
-
request?.addEventListener('success', function () {
|
|
133
|
-
count_ctx.total = request.result;
|
|
134
|
-
if (count_ctx.on_success) {
|
|
135
|
-
safeApply(count_ctx.on_success, [count_ctx]);
|
|
136
|
-
}
|
|
137
|
-
resolve(count_ctx);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
request?.addEventListener('error', function (event: any) {
|
|
141
|
-
count_ctx.error = cloneError((event as any).target.error);
|
|
142
|
-
if (count_ctx.on_error) {
|
|
143
|
-
safeApply(count_ctx.on_error, [count_ctx]);
|
|
144
|
-
}
|
|
145
|
-
reject(count_ctx);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export default indexesMethods;
|
package/src/store/index.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Store methods
|
|
4
|
-
* @module store
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { cloneError, DashContext, exists } from "../utilities";
|
|
8
|
-
|
|
9
|
-
// Store methods
|
|
10
|
-
export const storeMethods = {
|
|
11
|
-
/**
|
|
12
|
-
* Clear a store.
|
|
13
|
-
* @param clear_ctx
|
|
14
|
-
* @returns Promise<DashContext>
|
|
15
|
-
*/
|
|
16
|
-
clear: (clear_ctx: DashContext): Promise<DashContext> => {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
const request: IDBRequest<any> | undefined = clear_ctx.objectstore?.clear();
|
|
19
|
-
|
|
20
|
-
request?.addEventListener('success', () => {
|
|
21
|
-
if (clear_ctx.on_success) {
|
|
22
|
-
clear_ctx.on_success(clear_ctx); // Call the success callback here
|
|
23
|
-
}
|
|
24
|
-
resolve(clear_ctx);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
request?.addEventListener('error', (event) => {
|
|
28
|
-
clear_ctx.error = cloneError((event as any).target.error);
|
|
29
|
-
if (clear_ctx.on_error) {
|
|
30
|
-
clear_ctx.on_error(clear_ctx); // Call the error callback here
|
|
31
|
-
}
|
|
32
|
-
reject(clear_ctx);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Remove a store entry.
|
|
39
|
-
* @param remove_ctx
|
|
40
|
-
* @returns Promise<DashContext>
|
|
41
|
-
*/
|
|
42
|
-
remove: (remove_ctx: DashContext): Promise<DashContext> => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
const request: IDBRequest<any> | undefined = remove_ctx.objectstore?.delete(remove_ctx.key);
|
|
45
|
-
|
|
46
|
-
request?.addEventListener('success', () => {
|
|
47
|
-
if (remove_ctx.on_success) {
|
|
48
|
-
remove_ctx.on_success(remove_ctx); // Call the success callback here
|
|
49
|
-
}
|
|
50
|
-
resolve(remove_ctx);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
request?.addEventListener('error', (event) => {
|
|
54
|
-
remove_ctx.error = cloneError((event as any).target.error);
|
|
55
|
-
if (remove_ctx.on_error) {
|
|
56
|
-
remove_ctx.on_error(remove_ctx); // Call the error callback here
|
|
57
|
-
}
|
|
58
|
-
reject(remove_ctx);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Get a store entry.
|
|
65
|
-
* @param get_ctx
|
|
66
|
-
* @returns Promise<DashContext>
|
|
67
|
-
*/
|
|
68
|
-
get: (get_ctx: DashContext): Promise<DashContext> => {
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
const request: IDBRequest<any> | undefined = exists(get_ctx.index)
|
|
71
|
-
? get_ctx.objectstore?.index(get_ctx.index)?.get(get_ctx.key) as IDBRequest<any>
|
|
72
|
-
: get_ctx.objectstore?.get(get_ctx.key) as IDBRequest<any>;
|
|
73
|
-
|
|
74
|
-
request?.addEventListener('success', () => {
|
|
75
|
-
get_ctx.entry = request.result;
|
|
76
|
-
if (!get_ctx.entry) {
|
|
77
|
-
get_ctx.error = { message: 'missing', name: 'DashNoEntry' };
|
|
78
|
-
if (get_ctx.on_error) {
|
|
79
|
-
get_ctx.on_error(get_ctx); // Call the error callback here
|
|
80
|
-
}
|
|
81
|
-
reject(get_ctx);
|
|
82
|
-
} else {
|
|
83
|
-
if (get_ctx.on_success) {
|
|
84
|
-
get_ctx.on_success(get_ctx); // Call the success callback here
|
|
85
|
-
}
|
|
86
|
-
resolve(get_ctx);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
request?.addEventListener('error', (event) => {
|
|
91
|
-
get_ctx.error = cloneError((event as any).target.error);
|
|
92
|
-
if (get_ctx.on_error) {
|
|
93
|
-
get_ctx.on_error(get_ctx); // Call the error callback here
|
|
94
|
-
}
|
|
95
|
-
reject(get_ctx);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// Export the store methods
|
|
102
|
-
export default storeMethods;
|
package/src/stores/index.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stores methods.
|
|
3
|
-
* @Module stores
|
|
4
|
-
*/
|
|
5
|
-
import { cloneError, DashContext, exists, safeApply } from "../utilities";
|
|
6
|
-
|
|
7
|
-
// Store methods
|
|
8
|
-
export const storesMethods = {
|
|
9
|
-
/**
|
|
10
|
-
* Get all object stores from the current database.
|
|
11
|
-
* @param get_ctx The context object.
|
|
12
|
-
* @returns Promise<DashContext>
|
|
13
|
-
* @private
|
|
14
|
-
*/
|
|
15
|
-
get: function (get_ctx: DashContext) {
|
|
16
|
-
// This method retrieves all object stores synchronously or asynchronously via an on_success callback.
|
|
17
|
-
get_ctx.stores = get_ctx.db?.objectStoreNames;
|
|
18
|
-
safeApply(get_ctx.on_success, [get_ctx]);
|
|
19
|
-
},
|
|
20
|
-
/**
|
|
21
|
-
* Add a new object store to the current database.
|
|
22
|
-
* @param add_ctx The context object.
|
|
23
|
-
* @returns Promise<DashContext>
|
|
24
|
-
* @private
|
|
25
|
-
*/
|
|
26
|
-
add: function (add_ctx: DashContext) {
|
|
27
|
-
// This method adds a new object store in the database, creating a version change.
|
|
28
|
-
add_ctx.db = add_ctx.request?.result;
|
|
29
|
-
if (!add_ctx.db) {
|
|
30
|
-
throw new Error("Database is undefined");
|
|
31
|
-
}
|
|
32
|
-
const store = add_ctx.db.createObjectStore(add_ctx.store, {
|
|
33
|
-
keyPath: add_ctx.store_key_path || null,
|
|
34
|
-
autoIncrement: !!add_ctx.auto_increment
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (add_ctx.request) {
|
|
38
|
-
add_ctx.db = add_ctx.request.result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (add_ctx.indexes) {
|
|
42
|
-
// If there are indexes defined, we create them in the new store
|
|
43
|
-
add_ctx.indexes.forEach((idx: any) => {
|
|
44
|
-
store.createIndex(idx.name, idx.keyPath, {
|
|
45
|
-
unique: !!idx.unique,
|
|
46
|
-
multiEntry: !!idx.multiEntry
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
safeApply(add_ctx.on_success, [add_ctx]);
|
|
52
|
-
},
|
|
53
|
-
/**
|
|
54
|
-
* Remove an object store from the current database.
|
|
55
|
-
* @param remove_ctx The context object.
|
|
56
|
-
* @returns Promise<DashContext>
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
remove: function (remove_ctx: DashContext) {
|
|
60
|
-
// This method deletes a specified object store, triggering a version change.
|
|
61
|
-
remove_ctx.db?.deleteObjectStore(remove_ctx.store);
|
|
62
|
-
safeApply(remove_ctx.on_success, [remove_ctx]);
|
|
63
|
-
},
|
|
64
|
-
/**
|
|
65
|
-
* Clear all object stores in the current database.
|
|
66
|
-
* @param clear_ctx The context object.
|
|
67
|
-
* @returns Promise<DashContext>
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
clearAll: function (clear_ctx: DashContext) {
|
|
71
|
-
// This method clears all entries in all object stores in the current database.
|
|
72
|
-
const storeNames = Array.from(clear_ctx.db?.objectStoreNames || []);
|
|
73
|
-
const transaction = clear_ctx.db?.transaction(storeNames as any, "readwrite");
|
|
74
|
-
|
|
75
|
-
storeNames?.forEach((storeName: string) => {
|
|
76
|
-
const objectStore = transaction?.objectStore(storeName);
|
|
77
|
-
objectStore?.clear();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
transaction?.addEventListener('complete', () => {
|
|
81
|
-
safeApply(clear_ctx.on_success, [clear_ctx]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
transaction?.addEventListener('error', (event) => {
|
|
85
|
-
clear_ctx.error = cloneError((event as any).target.error);
|
|
86
|
-
safeApply(clear_ctx.on_error, [clear_ctx]);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
export default storesMethods;
|