@cocreate/indexeddb 1.17.0 → 1.17.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [1.17.1](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.17.0...v1.17.1) (2023-11-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * $storage, $database, $array are arrays ([b6374f8](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/b6374f84e4ff13751cc357bbba8d4c883380083f))
7
+ * meta name typo ([da33128](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/da331289589ea151f78ce25942e18e133f6b87f1))
8
+ * update crud methods ([c74ed56](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/c74ed5688bd9a25f4eb524064b799ad678bdcc57))
9
+ * updated date to ISO format with UTC timezone ([8bcc59a](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/8bcc59a7d715937c6de139dcb12951a686aa1cff))
10
+
1
11
  # [1.17.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.16.2...v1.17.0) (2023-11-03)
2
12
 
3
13
 
package/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- key="description"
14
+ name="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
16
  <meta
17
- key="keywords"
17
+ name="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.17.0",
3
+ "version": "1.17.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",
package/src/index.js CHANGED
@@ -22,9 +22,8 @@
22
22
  * For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app
23
23
  */
24
24
 
25
- import { ObjectId, dotNotationToObject, searchData, sortData, queryData, isValidDate } from '@cocreate/utils'
25
+ import { ObjectId, dotNotationToObject, searchData, sortData, queryData } from '@cocreate/utils'
26
26
 
27
- // let status = true;
28
27
  let indexedDbFunction
29
28
 
30
29
  function init() {
@@ -71,9 +70,7 @@ async function send(data) {
71
70
  await processDatabase(data, newData, type)
72
71
  } else {
73
72
  if (!data['timeStamp'])
74
- data['timeStamp'] = new Date()
75
- else
76
- data['timeStamp'] = new Date(data['timeStamp'])
73
+ data['timeStamp'] = new Date().toISOString();
77
74
 
78
75
  let databases = data.database;
79
76
  if (!databases && data.organization_id)
@@ -121,9 +118,9 @@ const processDatabase = (data, newData, type) => {
121
118
  if (data.$filter && data.$filter.query) {
122
119
  let isFilter = queryData(database, data.$filter.query)
123
120
  if (isFilter)
124
- newData.push({ $storage: 'indexeddb', ...database })
121
+ newData.push({ $storage: ['indexeddb'], ...database })
125
122
  } else
126
- newData.push({ $storage: 'indexeddb', ...database })
123
+ newData.push({ $storage: ['indexeddb'], ...database })
127
124
  }
128
125
 
129
126
  resolve()
@@ -274,9 +271,9 @@ async function processArray(data, newData, database, type) {
274
271
  if (data.$filter && data.$filter.query) {
275
272
  let isFilter = queryData({ name: objectStoreNames[i] }, data.$filter.query)
276
273
  if (isFilter)
277
- newData.push({ name: objectStoreNames, $storage: 'indexeddb', $database: database })
274
+ newData.push({ name: objectStoreNames, $storage: ['indexeddb'], $database: [database] })
278
275
  } else
279
- newData.push({ name: objectStoreNames[i], $storage: 'indexeddb', $database: database })
276
+ newData.push({ name: objectStoreNames[i], $storage: ['indexeddb'], $database: [database] })
280
277
  }
281
278
  } else {
282
279
  db.close()
@@ -324,7 +321,7 @@ async function processArray(data, newData, database, type) {
324
321
  }
325
322
 
326
323
  if (!error)
327
- newData.push({ name: array, $storage: 'indexeddb', $database: database, array })
324
+ newData.push({ name: array, $storage: ['indexeddb'], $database: [database] })
328
325
  else
329
326
  errorHandler(data, error, database)
330
327
 
@@ -361,7 +358,7 @@ async function processIndex(data, newData, database, array, type) {
361
358
  if (data.$filter && data.$filter.query)
362
359
  if (!(queryData({ name }, data.$filter.query))) continue
363
360
 
364
- newData.push({ name, $storage: 'indexeddb', $database: database, $array: array })
361
+ newData.push({ name, $storage: ['indexeddb'], $database: [database], $array: [array] })
365
362
  }
366
363
  db.close()
367
364
  } else {
@@ -398,10 +395,10 @@ async function processIndex(data, newData, database, array, type) {
398
395
  error = 'new index name already exist'
399
396
  }
400
397
  } else
401
- error = 'index does not exist'
398
+ error = 'index does not exist';
402
399
 
403
400
  if (!error)
404
- newData.push({ name: index, $storage: 'indexeddb', $database: database, $array: array })
401
+ newData.push({ name: index, $storage: ['indexeddb'], $database: [database], $array: [array] })
405
402
  else
406
403
  errorHandler(data, error, database, array)
407
404
 
@@ -415,6 +412,11 @@ async function processObject(data, newData, database, array, type) {
415
412
  let db = await processDatabase({ method: 'database.get', database })
416
413
 
417
414
  try {
415
+ if (!data[type])
416
+ data[type] = []
417
+ if (data[type] && !Array.isArray(data[type]))
418
+ data[type] = [data[type]]
419
+
418
420
  let isFilter
419
421
  if (data.$filter && data.$filter.query)
420
422
  isFilter = true
@@ -432,10 +434,6 @@ async function processObject(data, newData, database, array, type) {
432
434
  if (!array || !db)
433
435
  throw new Error({ error: "This is an error message.", db, array });
434
436
 
435
- if (!data[type])
436
- data[type] = []
437
- if (data[type] && !Array.isArray(data[type]))
438
- data[type] = [data[type]]
439
437
 
440
438
  if ((isFilter && !data[type].length) || data.isFilter)
441
439
  data[type] = [{ isFilter: 'isEmptyObjectFilter' }];
@@ -452,6 +450,8 @@ async function processObject(data, newData, database, array, type) {
452
450
  let upsert = data.upsert
453
451
 
454
452
  for (let i = 0; i < data[type].length; i++) {
453
+ const reference = { $storage: ['indexeddb'], $database: [database], $array: [array] }
454
+
455
455
  delete data[type][i].$storage
456
456
  delete data[type][i].$database
457
457
  delete data[type][i].$array
@@ -467,9 +467,7 @@ async function processObject(data, newData, database, array, type) {
467
467
  // TODO: user_id || clientId shohould be retrieved from CoCreate
468
468
  data[type][i]['created'] = { on: data.timeStamp, by: data.user_id || data.clientId }
469
469
  data[type][i] = await add(objectStore, data[type][i])
470
- data[type][i].$storage = 'indexeddb'
471
- data[type][i].$database = database
472
- data[type][i].$array = array
470
+ data[type][i] = { ...reference, ...data[type][i] }
473
471
 
474
472
  } else {
475
473
  if (data[type][i].$filter)
@@ -482,7 +480,8 @@ async function processObject(data, newData, database, array, type) {
482
480
  if (data[type][i].$upsert)
483
481
  upsert = data[type][i].$upsert
484
482
  // TODO: user_id || clientId shohould be retrieved from CoCreate
485
- data[type][i]['modified'] = { on: data.timeStamp, by: data.user_id || data.clientId }
483
+ if (!data[type][i].modified)
484
+ data[type][i].modified = { on: data.timeStamp, by: data.user_id || data.clientId }
486
485
  }
487
486
 
488
487
  let index = 0, limit, range, direction
@@ -563,7 +562,7 @@ async function processObject(data, newData, database, array, type) {
563
562
  continue
564
563
  }
565
564
 
566
- await openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators);
565
+ await openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators, reference);
567
566
 
568
567
  if (index)
569
568
  newData = newData.slice(index)
@@ -582,7 +581,7 @@ async function processObject(data, newData, database, array, type) {
582
581
  }
583
582
  }
584
583
 
585
- function openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators) {
584
+ function openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators, reference) {
586
585
  return new Promise(async (resolve, reject) => {
587
586
  const request = objectStore.openCursor(range || null, direction);// next, prev
588
587
 
@@ -616,9 +615,7 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
616
615
  if (update)
617
616
  data[type][i] = await put(objectStore, update)
618
617
  }
619
- data[type][i].$storage = 'indexeddb'
620
- data[type][i].$database = database
621
- data[type][i].$array = array
618
+ data[type][i] = { ...reference, ...data[type][i] }
622
619
 
623
620
  matchedLength++
624
621
 
@@ -647,13 +644,13 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
647
644
  }
648
645
 
649
646
  if (data[type][i]._id)
650
- data[type][i] = { $storage: 'indexeddb', $database: database, $array: array, ...result }
647
+ data[type][i] = { ...reference, ...result }
651
648
  else {
652
649
  let object = data[type].find(obj => obj._id && obj._id === result._id)
653
650
  if (object)
654
- object = { $storage: 'indexeddb', $database: database, $array: array, ...object, ...result }
651
+ object = { ...reference, ...object, ...result }
655
652
  else
656
- newData.push({ $storage: 'indexeddb', $database: database, $array: array, ...result })
653
+ newData.push({ ...reference, ...result })
657
654
  }
658
655
 
659
656
  matchedLength++
@@ -781,7 +778,6 @@ function createUpdate(update, data, globalOpertors) {
781
778
  function dotNotationToObjectUpdate(data, object = {}) {
782
779
  try {
783
780
  for (const key of Object.keys(data)) {
784
- let value = isValidDate(data[key])
785
781
  let newObject = object
786
782
  let oldObject = new Object(newObject)
787
783
  let keys = key.replace(/\[(\d+)\]/g, '.$1').split('.');
@@ -4,7 +4,7 @@ async function testArrays() {
4
4
  return;
5
5
  } else {
6
6
 
7
- let createObject = await CoCreate.indexeddb.process({
7
+ let createObject = await Coindex.createeddb.process({
8
8
  method: 'array.create',
9
9
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
10
10
  array: ['testArray', 'testArray1', 'testArray2']
@@ -12,13 +12,13 @@ async function testArrays() {
12
12
  })
13
13
  console.log('createObject', createObject)
14
14
 
15
- let readObject = await CoCreate.indexeddb.process({
15
+ let readObject = await Coindex.createeddb.process({
16
16
  method: 'array.read',
17
17
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
18
18
  })
19
19
  console.log('readObject', readObject)
20
20
 
21
- let updateObject = await CoCreate.indexeddb.process({
21
+ let updateObject = await Coindex.createeddb.process({
22
22
  method: 'array.update',
23
23
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
24
24
  array: { testArray: 'testArrayA' }
@@ -26,7 +26,7 @@ async function testArrays() {
26
26
  console.log('updateObject', updateObject)
27
27
 
28
28
 
29
- let deleteObject = await CoCreate.indexeddb.process({
29
+ let deleteObject = await Coindex.createeddb.process({
30
30
  method: 'array.delete',
31
31
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
32
32
  array: ['testArrayA', 'testArray1', 'testArray2']
package/test/databases.js CHANGED
@@ -3,26 +3,26 @@ async function testDatabases() {
3
3
  console.log("This browser doesn't support IndexedDB.");
4
4
  return;
5
5
  } else {
6
- let createDatabase = await CoCreate.indexeddb.process({
6
+ let createDatabase = await Coindex.createeddb.process({
7
7
  method: 'database.create',
8
8
  database: 'testDB',
9
9
  })
10
10
  console.log('createDatabase', createDatabase)
11
11
 
12
- let readDatabase = await CoCreate.indexeddb.process({
12
+ let readDatabase = await Coindex.createeddb.process({
13
13
  method: 'database.read',
14
14
  database: 'testDB',
15
15
  })
16
16
  console.log('readDatabase', readDatabase)
17
17
 
18
- let updateDatabase = await CoCreate.indexeddb.process({
18
+ let updateDatabase = await Coindex.createeddb.process({
19
19
  method: 'database.update',
20
20
  database: { testDB: 'testDatabase1' }
21
21
  })
22
22
  console.log('updateDatabase', updateDatabase)
23
23
 
24
24
 
25
- let deleteDatabase = await CoCreate.indexeddb.process({
25
+ let deleteDatabase = await Coindex.createeddb.process({
26
26
  method: 'database.delete',
27
27
  database: ['testDB', 'testDB1', 'testDB2'],
28
28
  })
package/test/documents.js CHANGED
@@ -4,7 +4,7 @@ async function testDocuments() {
4
4
  return;
5
5
  } else {
6
6
 
7
- let createObject = await CoCreate.indexeddb.process({
7
+ let createObject = await Coindex.createeddb.process({
8
8
  method: 'object.create',
9
9
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
10
10
  array: ['testArray', 'testArray1', 'testArray2'],
@@ -18,7 +18,7 @@ async function testDocuments() {
18
18
  console.log('createObject', createObject)
19
19
  let _id = createObject.object[0]._id
20
20
 
21
- let readObject = await CoCreate.indexeddb.process({
21
+ let readObject = await Coindex.createeddb.process({
22
22
  method: 'object.read',
23
23
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
24
24
  array: ['testArray', 'testArray1', 'testArray2'],
@@ -29,7 +29,7 @@ async function testDocuments() {
29
29
  })
30
30
  console.log('readObject', readObject)
31
31
 
32
- let updateObject = await CoCreate.indexeddb.process({
32
+ let updateObject = await Coindex.createeddb.process({
33
33
  method: 'object.update',
34
34
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
35
35
  array: ['testArray', 'testArray1', 'testArray2'],
@@ -43,7 +43,7 @@ async function testDocuments() {
43
43
  console.log('updateObject', updateObject)
44
44
 
45
45
 
46
- let deleteObject = await CoCreate.indexeddb.process({
46
+ let deleteObject = await Coindex.createeddb.process({
47
47
  method: 'object.delete',
48
48
  database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
49
49
  array: ['testArray', 'testArray1', 'testArray2'],
@@ -60,7 +60,7 @@ async function testDocuments() {
60
60
  })
61
61
  console.log('deleteObject', deleteObject)
62
62
 
63
- // let deleteDatabase = await CoCreate.indexeddb.deleteDatabase({
63
+ // let deleteDatabase = await Coindex.createeddb.deleteDatabase({
64
64
  // database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
65
65
  // })
66
66
  // console.log('deleteDatabase', deleteDatabase)
package/test/indexes.js CHANGED
@@ -3,7 +3,7 @@ async function testIndexes() {
3
3
  console.log("This browser doesn't support IndexedDB.");
4
4
  return;
5
5
  } else {
6
- let createIndexes = await CoCreate.indexeddb.createIndex({
6
+ let createIndexes = await Coindex.createeddb.createIndex({
7
7
  database: ['testDB', 'testDB1', 'testDB2'],
8
8
  array: ['testCollection', 'testCollection1', 'testCollection2'],
9
9
  index: 'testIndexes'
@@ -11,20 +11,20 @@ async function testIndexes() {
11
11
  })
12
12
  console.log('createIndexes', createIndexes)
13
13
 
14
- let readIndexes = await CoCreate.indexeddb.readIndex({
14
+ let readIndexes = await Coindex.createeddb.readIndex({
15
15
  database: ['testDB', 'testDB1', 'testDB2'],
16
16
  array: ['testCollection', 'testCollection1', 'testCollection2']
17
17
  })
18
18
  console.log('readIndexes', readIndexes)
19
19
 
20
- let updateIndexes = await CoCreate.indexeddb.updateIndex({
20
+ let updateIndexes = await Coindex.createeddb.updateIndex({
21
21
  database: ['testDB', 'testDB1', 'testDB2'],
22
22
  array: ['testCollection', 'testCollection1', 'testCollection2'],
23
23
  index: { testIndexes: 'testIndexes1' }
24
24
  })
25
25
  console.log('updateIndexes', updateIndexes)
26
26
 
27
- let deleteIndexes = await CoCreate.indexeddb.deleteIndex({
27
+ let deleteIndexes = await Coindex.createeddb.deleteIndex({
28
28
  database: ['testDB', 'testDB1', 'testDB2'],
29
29
  array: ['testCollection', 'testCollection1', 'testCollection2'],
30
30
  index: 'testIndexes1'