@cocreate/indexeddb 1.29.0 → 2.0.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/.github/FUNDING.yml +1 -1
- package/.github/workflows/automated.yml +18 -7
- package/CHANGELOG.md +498 -456
- package/CONTRIBUTING.md +6 -6
- package/CoCreate.config.js +2 -2
- package/README.md +18 -18
- package/demo/index.html +1 -1
- package/docs/index.html +4 -4
- package/package.json +7 -7
- package/src/index.js +28 -2
- package/test/index.html +1 -1
- package/test/unsorted-response.test.cjs +66 -4
- /package/{release.config.js → release.config.cjs} +0 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# Contributing to CoCreate-indexeddb
|
|
2
2
|
|
|
3
|
-
This project is work of [many contributors](https://github.com/
|
|
4
|
-
You're encouraged to submit [pull requests](https://github.com/
|
|
5
|
-
[propose features and discuss issues](https://github.com/
|
|
3
|
+
This project is work of [many contributors](https://github.com/CoCreateJS/indexeddb/graphs/contributors).
|
|
4
|
+
You're encouraged to submit [pull requests](https://github.com/CoCreateJS/indexeddb/pulls),
|
|
5
|
+
[propose features and discuss issues](https://github.com/CoCreateJS/indexeddb/issues).
|
|
6
6
|
|
|
7
7
|
In the examples below, substitute your Github username for `contributor` in URLs.
|
|
8
8
|
|
|
9
9
|
## Fork the Project
|
|
10
10
|
|
|
11
|
-
Fork the [project on Github](https://github.com/
|
|
11
|
+
Fork the [project on Github](https://github.com/CoCreateJS/indexeddb) and check out your copy.
|
|
12
12
|
|
|
13
13
|
```
|
|
14
14
|
git clone https://github.com/contributor/CoCreate-indexeddb.git
|
|
15
15
|
cd CoCreate-indexeddb
|
|
16
|
-
git remote add upstream https://
|
|
16
|
+
git remote add upstream https://github.com/CoCreateJS/indexeddb.git
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Create a Topic Branch
|
|
@@ -75,7 +75,7 @@ git push origin my-feature-branch
|
|
|
75
75
|
|
|
76
76
|
## Make a Pull Request
|
|
77
77
|
|
|
78
|
-
Go to [https://github.com/
|
|
78
|
+
Go to [https://github.com/CoCreateJS/indexeddb](https://github.com/CoCreateJS/indexeddb) and select your feature branch.
|
|
79
79
|
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
|
80
80
|
|
|
81
81
|
## Rebase
|
package/CoCreate.config.js
CHANGED
|
@@ -12,8 +12,8 @@ module.exports = {
|
|
|
12
12
|
"pathname": "/docs/indexeddb/index.html",
|
|
13
13
|
"src": "{{./docs/index.html}}",
|
|
14
14
|
"host": [
|
|
15
|
-
"
|
|
16
|
-
"general.
|
|
15
|
+
"CoCreateJS.com",
|
|
16
|
+
"general.CoCreateJS.com"
|
|
17
17
|
],
|
|
18
18
|
"directory": "indexeddb",
|
|
19
19
|
"content-type": "{{content-type}}",
|
package/README.md
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
# CoCreate-indexeddb
|
|
2
2
|
|
|
3
|
-
an indexeddb wrapper. Easily crud data using HTML5 attribute API and/or JavaScript API. Take it for a spin in our [playground!](https://
|
|
3
|
+
an indexeddb wrapper. Easily crud data using HTML5 attribute API and/or JavaScript API. Take it for a spin in our [playground!](https://CoCreateJS.com/docs/indexeddb)
|
|
4
4
|
|
|
5
|
-

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
10
|

|
|
11
11
|
|
|
12
|
-

|
|
13
13
|
|
|
14
|
-
## [Docs & Demo](https://
|
|
14
|
+
## [Docs & Demo](https://CoCreateJS.com/docs/indexeddb)
|
|
15
15
|
|
|
16
|
-
For a complete guide and working demo refer to the [doumentation](https://
|
|
16
|
+
For a complete guide and working demo refer to the [doumentation](https://CoCreateJS.com/docs/indexeddb)
|
|
17
17
|
|
|
18
18
|
## CDN
|
|
19
19
|
|
|
20
20
|
```html
|
|
21
|
-
<script src="https://cdn.
|
|
21
|
+
<script src="https://cdn.CoCreateJS.com/indexeddb/latest/CoCreate-indexeddb.min.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
```html
|
|
25
|
-
<script src="https://cdn.
|
|
25
|
+
<script src="https://cdn.CoCreateJS.com/indexeddb/latest/CoCreate-indexeddb.min.css"></script>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## NPM
|
|
@@ -50,13 +50,13 @@ $ yarn install @cocreate/indexeddb
|
|
|
50
50
|
|
|
51
51
|
# Announcements
|
|
52
52
|
|
|
53
|
-
All updates to this library are documented in our [CHANGELOG](https://github.com/
|
|
53
|
+
All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreateJS/indexeddb/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreateJS/indexeddb/releases). You may also subscribe to email for releases and breaking changes.
|
|
54
54
|
|
|
55
55
|
<a name="roadmap"></a>
|
|
56
56
|
|
|
57
57
|
# Roadmap
|
|
58
58
|
|
|
59
|
-
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/
|
|
59
|
+
If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreateJS/indexeddb/issues) and [pull requests](https://github.com/CoCreateJS/indexeddb/pulls). We would love to hear your feedback.
|
|
60
60
|
|
|
61
61
|
<a name="about"></a>
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ If you are interested in the future direction of this project, please take a loo
|
|
|
64
64
|
|
|
65
65
|
CoCreate-indexeddb is guided and supported by the CoCreate Developer Experience Team.
|
|
66
66
|
|
|
67
|
-
Please Email the Developer Experience Team [here](mailto:develop@
|
|
67
|
+
Please Email the Developer Experience Team [here](mailto:develop@CoCreateJS.com) in case of any queries.
|
|
68
68
|
|
|
69
69
|
CoCreate-indexeddb is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
|
|
70
70
|
|
|
@@ -72,9 +72,9 @@ CoCreate-indexeddb is maintained and funded by CoCreate. The names and logos for
|
|
|
72
72
|
|
|
73
73
|
# How to Contribute
|
|
74
74
|
|
|
75
|
-
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/
|
|
75
|
+
We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreateJS/indexeddb/blob/master/CONTRIBUTING.md) guide for details.
|
|
76
76
|
|
|
77
|
-
We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/
|
|
77
|
+
We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreateJS/indexeddb/issues) and [pull requests](https://github.com/CoCreateJS/indexeddb/pulls) or merely upvote or comment on existing issues or pull requests.
|
|
78
78
|
|
|
79
79
|
We appreciate your continued support, thank you!
|
|
80
80
|
|
|
@@ -84,8 +84,8 @@ We appreciate your continued support, thank you!
|
|
|
84
84
|
|
|
85
85
|
This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.
|
|
86
86
|
|
|
87
|
-
- **Open Source Use**: For open-source projects and non-commercial use, this software is available under the AGPLv3. The AGPLv3 allows you to freely use, modify, and distribute this software, provided that all modifications and derivative works are also licensed under the AGPLv3. For the full license text, see the [LICENSE file](https://github.com/
|
|
87
|
+
- **Open Source Use**: For open-source projects and non-commercial use, this software is available under the AGPLv3. The AGPLv3 allows you to freely use, modify, and distribute this software, provided that all modifications and derivative works are also licensed under the AGPLv3. For the full license text, see the [LICENSE file](https://github.com/CoCreateJS/indexeddb/blob/master/LICENSE).
|
|
88
88
|
|
|
89
|
-
- **Commercial Use**: For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our [website](https://
|
|
89
|
+
- **Commercial Use**: For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our [website](https://CoCreateJS.com). This license permits proprietary use and modification of the software without the copyleft requirements of the AGPLv3. It is ideal for integrating this software into proprietary commercial products and applications.
|
|
90
90
|
|
|
91
91
|
If you have not purchased a commercial license and intend to use this software for commercial purposes, you are required to sign up for an API key on our website.
|
package/demo/index.html
CHANGED
package/docs/index.html
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
rel="icon"
|
|
10
10
|
type="image/png"
|
|
11
11
|
sizes="32x32"
|
|
12
|
-
href="https://
|
|
12
|
+
href="https://CoCreateJS.com/images/favicon.ico" />
|
|
13
13
|
<meta
|
|
14
14
|
name="description"
|
|
15
15
|
content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
share-width="500"
|
|
37
37
|
share-media="https://via.placeholder.com/300/09f/fff.png">
|
|
38
38
|
<a
|
|
39
|
-
href="https://github.com/
|
|
39
|
+
href="https://github.com/CoCreateJS/CoCreate-indexeddb"
|
|
40
40
|
target="_blank"
|
|
41
41
|
class="margin-right:15px"
|
|
42
42
|
><i src="/assets/svg/github.svg"></i
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
<pre
|
|
81
81
|
class="margin-top:15px"><code class="language-javascript">npm install cocreate-indexeddb</code></pre>
|
|
82
82
|
<p class="padding:10px_0px">Or you can use cdn link:</p>
|
|
83
|
-
<pre><code class="language-javascript">https://cdn.
|
|
83
|
+
<pre><code class="language-javascript">https://cdn.CoCreateJS.com/js/CoCreate-indexeddb.min.js</code></pre>
|
|
84
84
|
|
|
85
85
|
<h2
|
|
86
86
|
class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
|
|
@@ -225,6 +225,6 @@
|
|
|
225
225
|
</div>
|
|
226
226
|
|
|
227
227
|
<!--CoCreateJS-->
|
|
228
|
-
<script src="https://
|
|
228
|
+
<script src="https://CoCreateJS.com/dist/CoCreate.js"></script>
|
|
229
229
|
</body>
|
|
230
230
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A simple indexeddb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indexeddb",
|
|
@@ -22,25 +22,25 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://
|
|
25
|
+
"url": "git+https://github.com/CoCreateJS/indexeddb.git"
|
|
26
26
|
},
|
|
27
27
|
"author": "CoCreate LLC",
|
|
28
28
|
"license": "AGPL-3.0",
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/CoCreateJS/indexeddb/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://
|
|
32
|
+
"homepage": "https://CoCreateJS.com/docs/indexeddb",
|
|
33
33
|
"funding": {
|
|
34
34
|
"type": "GitHub Sponsors ❤",
|
|
35
|
-
"url": "https://github.com/sponsors/
|
|
35
|
+
"url": "https://github.com/sponsors/CoCreateJS"
|
|
36
36
|
},
|
|
37
37
|
"type": "module",
|
|
38
38
|
"main": "./src/index.js",
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@cocreate/webpack": "^
|
|
40
|
+
"@cocreate/webpack": "^2.0.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@cocreate/utils": "^
|
|
43
|
+
"@cocreate/utils": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"allowScripts": {
|
|
46
46
|
"@cocreate/utils@1.42.2": true,
|
package/src/index.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* Commercial Licensing Information:
|
|
20
20
|
* For commercial use of this software without the copyleft provisions of the AGPLv3,
|
|
21
21
|
* you must obtain a commercial license from CoCreate LLC.
|
|
22
|
-
* For details, visit <https://
|
|
22
|
+
* For details, visit <https://CoCreateJS.com/licenses/> or contact us at sales@CoCreateJS.com
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import {
|
|
@@ -116,6 +116,12 @@ function setStatus(value) {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Route a CoCreate CRUD request to the matching database, array, or object operation.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
* @environment client
|
|
124
|
+
*/
|
|
119
125
|
async function send(data) {
|
|
120
126
|
try {
|
|
121
127
|
let newData = [];
|
|
@@ -374,7 +380,7 @@ async function processArray(data, newData, database, type) {
|
|
|
374
380
|
);
|
|
375
381
|
if (isFilter)
|
|
376
382
|
newData.push({
|
|
377
|
-
name: objectStoreNames,
|
|
383
|
+
name: objectStoreNames[i],
|
|
378
384
|
$storage: ["indexeddb"],
|
|
379
385
|
$database: [database]
|
|
380
386
|
});
|
|
@@ -624,6 +630,7 @@ async function processObject(data, newData, database, array, type) {
|
|
|
624
630
|
if (!data[type][i]._id)
|
|
625
631
|
data[type][i]["_id"] = ObjectId().toString();
|
|
626
632
|
data[type][i] = dotNotationToObject(data[type][i]);
|
|
633
|
+
delete data[type][i].modified;
|
|
627
634
|
|
|
628
635
|
// TODO: user_id || clientId shohould be retrieved from CoCreate
|
|
629
636
|
const audit = {
|
|
@@ -650,6 +657,8 @@ async function processObject(data, newData, database, array, type) {
|
|
|
650
657
|
on: data.timeStamp,
|
|
651
658
|
by: data.user_id || data.clientId
|
|
652
659
|
};
|
|
660
|
+
// Remove legacy object audit metadata from existing records.
|
|
661
|
+
data[type][i].modified = undefined;
|
|
653
662
|
}
|
|
654
663
|
|
|
655
664
|
let index = 0,
|
|
@@ -864,6 +873,7 @@ function openCursor(
|
|
|
864
873
|
data[type][i],
|
|
865
874
|
globalOperators
|
|
866
875
|
);
|
|
876
|
+
delete data[type][i].modified;
|
|
867
877
|
if (update) {
|
|
868
878
|
await put(objectStore, update);
|
|
869
879
|
data[type][i].$update = update;
|
|
@@ -897,6 +907,7 @@ function openCursor(
|
|
|
897
907
|
data[type][i],
|
|
898
908
|
globalOperators
|
|
899
909
|
);
|
|
910
|
+
delete data[type][i].modified;
|
|
900
911
|
if (update) await cursorUpdate(cursor, update);
|
|
901
912
|
result = data[type][i];
|
|
902
913
|
result.$update = update;
|
|
@@ -1070,3 +1081,18 @@ function errorHandler(data, error, database, array) {
|
|
|
1070
1081
|
init();
|
|
1071
1082
|
|
|
1072
1083
|
export default { send, ObjectId };
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Object identifier constructor exposed by the IndexedDB adapter.
|
|
1087
|
+
*
|
|
1088
|
+
* @name ObjectId
|
|
1089
|
+
* @public
|
|
1090
|
+
* @environment client
|
|
1091
|
+
*/
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* A simple indexeddb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.
|
|
1095
|
+
*
|
|
1096
|
+
* @module indexeddb
|
|
1097
|
+
* @environment client
|
|
1098
|
+
*/
|
package/test/index.html
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<body>
|
|
17
17
|
<!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
|
|
18
|
-
<script src="https://
|
|
18
|
+
<script src="https://CoCreateJS.com/dist/CoCreate.js"></script>
|
|
19
19
|
<!-- <script src="../../../CoCreateJS/dist/indexeddb-chunk.js"></script> -->
|
|
20
20
|
<script src="./operators.js"></script>
|
|
21
21
|
<script src="./databases.js"></script>
|
|
@@ -4,14 +4,18 @@ const path = require('node:path');
|
|
|
4
4
|
const vm = require('node:vm');
|
|
5
5
|
const test = require('node:test');
|
|
6
6
|
|
|
7
|
-
async function load() {
|
|
8
|
-
const context = vm.createContext({ console });
|
|
7
|
+
async function load(indexedDB) {
|
|
8
|
+
const context = vm.createContext({ console, indexedDB });
|
|
9
9
|
const source = fs.readFileSync(path.join(__dirname, '../src/index.js'), 'utf8');
|
|
10
|
-
const module = new vm.SourceTextModule(source + '\nexport { createData, getSortPlan };', { context });
|
|
10
|
+
const module = new vm.SourceTextModule(source + '\nexport { createData, getSortPlan, processArray, processDatabase };', { context });
|
|
11
11
|
await module.link(() => new vm.SyntheticModule([
|
|
12
12
|
'ObjectId', 'dotNotationToObject', 'searchData', 'sortData',
|
|
13
13
|
'queryData', 'createUpdate', 'isEqualArray', 'isEqualObject'
|
|
14
|
-
], function () {
|
|
14
|
+
], function () {
|
|
15
|
+
this.setExport('queryData', (data, query) =>
|
|
16
|
+
Object.entries(query).every(([key, value]) => data[key] === value)
|
|
17
|
+
);
|
|
18
|
+
}, { context }));
|
|
15
19
|
await module.evaluate();
|
|
16
20
|
return module.namespace;
|
|
17
21
|
}
|
|
@@ -40,3 +44,61 @@ test('sort planning supports absent, empty and named sort fields', async () => {
|
|
|
40
44
|
assert.equal(getSortPlan({ sort: [{ key: 'name', direction: 'desc' }] }).indexName, 'name');
|
|
41
45
|
assert.equal(getSortPlan({ sort: [{ key: 'name', direction: 'desc' }] }).direction, 'prev');
|
|
42
46
|
});
|
|
47
|
+
|
|
48
|
+
test('filtered array reads return one scalar name per matching object store', async () => {
|
|
49
|
+
const objectStoreNames = ['users', 'posts', 'events'];
|
|
50
|
+
const indexedDB = {
|
|
51
|
+
open() {
|
|
52
|
+
const request = {
|
|
53
|
+
result: {
|
|
54
|
+
objectStoreNames,
|
|
55
|
+
close() {}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
queueMicrotask(() => request.onsuccess());
|
|
59
|
+
return request;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const { processArray } = await load(indexedDB);
|
|
63
|
+
const data = {
|
|
64
|
+
method: 'array.read',
|
|
65
|
+
array: [],
|
|
66
|
+
filter: { query: { name: 'posts' } }
|
|
67
|
+
};
|
|
68
|
+
const result = [];
|
|
69
|
+
|
|
70
|
+
await processArray(data, result, 'app-database', 'array');
|
|
71
|
+
|
|
72
|
+
assert.deepEqual(result.map(({ name }) => name), ['posts']);
|
|
73
|
+
assert.equal(typeof result[0].name, 'string');
|
|
74
|
+
assert.deepEqual(Array.from(result[0].$database), ['app-database']);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('database reads return database objects with scalar names and storage metadata', async () => {
|
|
78
|
+
const indexedDB = {
|
|
79
|
+
databases: async () => [
|
|
80
|
+
{ name: 'app-database', version: 3 },
|
|
81
|
+
{ name: 'cache-database', version: 1 }
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
const { createData, processDatabase } = await load(indexedDB);
|
|
85
|
+
const data = { method: 'database.read' };
|
|
86
|
+
const result = [];
|
|
87
|
+
|
|
88
|
+
await processDatabase(data, result, 'database');
|
|
89
|
+
const response = createData(data, result, 'database');
|
|
90
|
+
|
|
91
|
+
assert.deepEqual(
|
|
92
|
+
Array.from(response.database, ({ name }) => name),
|
|
93
|
+
['app-database', 'cache-database']
|
|
94
|
+
);
|
|
95
|
+
assert.equal(typeof response.database[0].name, 'string');
|
|
96
|
+
assert.deepEqual(
|
|
97
|
+
Array.from(response.database, ({ version }) => version),
|
|
98
|
+
[3, 1]
|
|
99
|
+
);
|
|
100
|
+
assert.deepEqual(
|
|
101
|
+
Array.from(response.database[0].$storage),
|
|
102
|
+
['indexeddb']
|
|
103
|
+
);
|
|
104
|
+
});
|
|
File without changes
|