@cocreate/indexeddb 1.16.2 → 1.17.0

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,20 @@
1
+ # [1.17.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.16.2...v1.17.0) (2023-11-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * favicon.ico path ([3ea941e](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/3ea941e1e70879aa171ec3b98a81dc3769ec80f2))
7
+ * get.database updated to database.get ([b8058c6](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/b8058c6bbe5682d9bc7f29775b3f306babcd5108))
8
+ * relocated $filter conditions to after index is open ([349f7ff](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/349f7ff33b08ba0da77a313135523b6ccf3a9b41))
9
+ * transaction bug ([6016c07](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/6016c07c56b8dda63281783e810f4747d6e59d80))
10
+ * update dependencies to the lates versions ([4bcf0b2](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/4bcf0b223a73d8e73aea2083abf37c066f8c1d3d))
11
+ * update method to use object.update etc ([6b47872](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/6b47872704e19f7ba9cab7b544dfbad77aeed377))
12
+
13
+
14
+ ### Features
15
+
16
+ * morph data[type] so the object can be synced across multiple storage, database, array ([8d3afb4](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/8d3afb487ab4d4709c8bcc2ded6bf8d2ffaa0085))
17
+
1
18
  ## [1.16.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.16.1...v1.16.2) (2023-10-26)
2
19
 
3
20
 
package/demo/index.html CHANGED
@@ -6,9 +6,9 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
7
7
  <link
8
8
  rel="icon"
9
- href="https://cdn.cocreate.app/favicon.ico"
10
- type="image/ico"
11
- sizes="16x16" />
9
+ type="image/png"
10
+ sizes="32x32"
11
+ href="../assets/favicon.ico" />
12
12
  <title>indexeddb | CoCreateJS</title>
13
13
  <link rel="manifest" href="/manifest.webmanifest" />
14
14
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.16.2",
3
+ "version": "1.17.0",
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",
@@ -58,6 +58,6 @@
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
60
  "dependencies": {
61
- "@cocreate/utils": "^1.26.1"
61
+ "@cocreate/utils": "^1.26.2"
62
62
  }
63
63
  }
package/src/index.js CHANGED
@@ -63,18 +63,13 @@ async function send(data) {
63
63
  try {
64
64
  let newData = [];
65
65
 
66
- let type = data.method.split('.');
67
- type = type[type.length - 1];
68
-
66
+ let type = data.method.split('.')[0];
69
67
  if (type === 'database') {
70
- if (data.method === 'get.database') {
68
+ if (data.method === 'database.get') {
71
69
  return await processDatabase(data)
72
70
  } else
73
71
  await processDatabase(data, newData, type)
74
72
  } else {
75
- if (data.request)
76
- data[type] = data.request
77
-
78
73
  if (!data['timeStamp'])
79
74
  data['timeStamp'] = new Date()
80
75
  else
@@ -117,13 +112,10 @@ const processDatabase = (data, newData, type) => {
117
112
  return new Promise((resolve, reject) => {
118
113
  if (!data)
119
114
  data = {}
120
- if (data.request)
121
- data[type] = data.request
122
-
123
- // if (!data['timeStamp'])
124
- data['timeStamp'] = new Date(data['timeStamp'])
115
+ if (!data[type])
116
+ data[type] = []
125
117
 
126
- if (data.method == 'read.database') {
118
+ if (data.method == 'database.read') {
127
119
  indexedDB.databases().then((databases) => {
128
120
  for (let database of databases) {
129
121
  if (data.$filter && data.$filter.query) {
@@ -138,7 +130,7 @@ const processDatabase = (data, newData, type) => {
138
130
  })
139
131
  } else {
140
132
  let databases
141
- if (data.method == 'update.database')
133
+ if (data.method == 'database.update')
142
134
  databases = Object.keys(data.database)
143
135
  else
144
136
  databases = data.database;
@@ -149,12 +141,12 @@ const processDatabase = (data, newData, type) => {
149
141
  for (let i = 0; i < databases.length; i++) {
150
142
  let openRequest, database = databases[i];
151
143
  switch (data.method) {
152
- case 'get.database':
153
- case 'create.database':
154
- case 'update.database':
144
+ case 'database.get':
145
+ case 'database.create':
146
+ case 'database.update':
155
147
  openRequest = indexedDB.open(database);
156
148
  break;
157
- case 'delete.database':
149
+ case 'database.delete':
158
150
  openRequest = indexedDB.deleteprocessDatabase(database);
159
151
  break;
160
152
  default:
@@ -165,7 +157,7 @@ const processDatabase = (data, newData, type) => {
165
157
  openRequest.onsuccess = function () {
166
158
  let db = openRequest.result;
167
159
 
168
- if (data.method == 'update.database') {
160
+ if (data.method == 'database.update') {
169
161
  let objectStoreNames = Array.from(db.objectStoreNames)
170
162
  for (let array of objectStoreNames) {
171
163
  let request = array.openCursor();
@@ -232,7 +224,7 @@ const processDatabase = (data, newData, type) => {
232
224
 
233
225
  request.onsuccess = function (event) {
234
226
  if (databases.length - 1 === i) {
235
- if (data.method == 'get.database')
227
+ if (data.method == 'database.get')
236
228
  resolve(event.target.result)
237
229
  else
238
230
  resolve(data)
@@ -242,7 +234,7 @@ const processDatabase = (data, newData, type) => {
242
234
  request.onerror = function (event) {
243
235
  errorHandler(data, event.target.error, database, array)
244
236
  if (databases.length - 1 === i) {
245
- if (data.method == 'get.database')
237
+ if (data.method == 'database.get')
246
238
  resolve(event.target.result)
247
239
  else
248
240
  resolve(data)
@@ -250,7 +242,7 @@ const processDatabase = (data, newData, type) => {
250
242
  };
251
243
 
252
244
  } else if (databases.length - 1 === i) {
253
- if (data.method == 'get.database')
245
+ if (data.method == 'database.get')
254
246
  resolve(db)
255
247
  else
256
248
  resolve(data)
@@ -271,10 +263,10 @@ const processDatabase = (data, newData, type) => {
271
263
  }
272
264
 
273
265
  async function processArray(data, newData, database, type) {
274
- let db = await processDatabase({ method: 'get.database', database })
266
+ let db = await processDatabase({ method: 'database.get', database })
275
267
 
276
268
  let objectStoreNames = Array.from(db.objectStoreNames)
277
- if (data.method == 'read.array') {
269
+ if (data.method == 'array.read') {
278
270
  if (!data[type])
279
271
  data[type] = []
280
272
 
@@ -289,12 +281,12 @@ async function processArray(data, newData, database, type) {
289
281
  } else {
290
282
  db.close()
291
283
 
292
- let request = await processDatabase({ method: 'get.database', database, upgrade: true })
284
+ let request = await processDatabase({ method: 'database.get', database, upgrade: true })
293
285
  await new Promise((resolve) => {
294
286
  request.onupgradeneeded = function (event) {
295
287
  let db = event.target.result
296
288
  let arrays
297
- if (data.method == 'update.array')
289
+ if (data.method == 'array.update')
298
290
  arrays = Object.keys(data[type])
299
291
  else
300
292
  arrays = data[type];
@@ -305,20 +297,20 @@ async function processArray(data, newData, database, type) {
305
297
  let error, array = arrays[i]
306
298
 
307
299
  let arrayExist = db.objectStoreNames.contains(array)
308
- if (arrayExist && data.method == 'create.array') {
300
+ if (arrayExist && data.method == 'array.create') {
309
301
  error = 'array already exists'
310
- } else if (data.method == 'delete.array') {
302
+ } else if (data.method == 'array.delete') {
311
303
  if (objectStoreNames.includes(array)) {
312
304
  db.deleteObjectStore(array);
313
305
  } else {
314
306
  error = 'the array does not exist'
315
307
  }
316
308
  } else {
317
- if (!arrayExist && data.method == 'update.array')
309
+ if (!arrayExist && data.method == 'array.update')
318
310
  array = data[type][arrays[i]]
319
311
 
320
312
  if (arrayExist) {
321
- if (data.method == 'update.array') {
313
+ if (data.method == 'array.update') {
322
314
  let transaction = event.target.transaction;
323
315
  let objectStore = transaction.objectStore(array);
324
316
 
@@ -327,7 +319,7 @@ async function processArray(data, newData, database, type) {
327
319
  else
328
320
  error = 'An array with the new name already exist'
329
321
  }
330
- } else if (data.method == 'update.array')
322
+ } else if (data.method == 'array.update')
331
323
  error = 'array does not exists'
332
324
  }
333
325
 
@@ -355,7 +347,7 @@ async function processArray(data, newData, database, type) {
355
347
  }
356
348
 
357
349
  async function processIndex(data, newData, database, array, type) {
358
- let db = await processDatabase({ method: 'get.database', database })
350
+ let db = await processDatabase({ method: 'database.get', database })
359
351
  let arrayExist = db.objectStoreNames.contains(array)
360
352
  if (arrayExist) {
361
353
  // ToDO: switch here to types
@@ -363,7 +355,7 @@ async function processIndex(data, newData, database, array, type) {
363
355
  let objectStore = transaction.objectStore(array);
364
356
  let indexNames = Array.from(objectStore.indexNames)
365
357
 
366
- if (data.method == 'read.index') {
358
+ if (data.method == 'index.read') {
367
359
  for (let i = 0; i < indexNames.length; i++) {
368
360
  let name = indexNames[i]
369
361
  if (data.$filter && data.$filter.query)
@@ -375,7 +367,7 @@ async function processIndex(data, newData, database, array, type) {
375
367
  } else {
376
368
  db.close()
377
369
  let indexes
378
- if (data.method == 'update.index')
370
+ if (data.method == 'index.update')
379
371
  indexes = Object.keys(data[type])
380
372
  else
381
373
  indexes = data[type];
@@ -385,20 +377,20 @@ async function processIndex(data, newData, database, array, type) {
385
377
 
386
378
  for (let i = 0; i < indexes.length; i++) {
387
379
  let error, index = indexes[i]
388
- db = await processDatabase({ method: 'get.database', database, upgrade: true })
380
+ db = await processDatabase({ method: 'database.get', database, upgrade: true })
389
381
  let transaction = db.transaction;
390
382
  let objectStore = transaction.objectStore(array);
391
383
  let indexExist = indexNames.includes(index)
392
384
 
393
- if (data.method == 'create.index') {
385
+ if (data.method == 'index.create') {
394
386
  if (!indexExist)
395
387
  objectStore.createIndex(index, index, { unique: false })
396
388
  else
397
389
  error = 'index already exist'
398
390
  } else if (indexExist) {
399
- if (data.method == 'delete.index')
391
+ if (data.method == 'index.delete')
400
392
  objectStore.deleteIndex(index)
401
- else if (data.method == 'update.index' && !indexNames.includes(data[type][indexes[i]])) {
393
+ else if (data.method == 'index.update' && !indexNames.includes(data[type][indexes[i]])) {
402
394
  if (!indexNames.includes(data[type][indexes[i]])) {
403
395
  let indexObj = objectStore.index(index);
404
396
  index = indexObj.name = data[type][indexes[i]];
@@ -420,7 +412,7 @@ async function processIndex(data, newData, database, array, type) {
420
412
  }
421
413
 
422
414
  async function processObject(data, newData, database, array, type) {
423
- let db = await processDatabase({ method: 'get.database', database })
415
+ let db = await processDatabase({ method: 'database.get', database })
424
416
 
425
417
  try {
426
418
  let isFilter
@@ -429,9 +421,9 @@ async function processObject(data, newData, database, array, type) {
429
421
 
430
422
  let arrayExist = db.objectStoreNames.contains(array)
431
423
  if (!arrayExist) {
432
- if (data.method == 'create.object' || data.method == 'update.object') {
433
- db.close()
434
- db = await processDatabase({ method: 'get.database', database, array })
424
+ db.close()
425
+ if (data.method == 'object.create' || data.method == 'object.update') {
426
+ db = await processDatabase({ method: 'database.get', database, array })
435
427
  } else {
436
428
  return errorHandler(data, "array does not exist", database, array)
437
429
  }
@@ -445,11 +437,12 @@ async function processObject(data, newData, database, array, type) {
445
437
  if (data[type] && !Array.isArray(data[type]))
446
438
  data[type] = [data[type]]
447
439
 
448
- if (isFilter && !data[type].length)
449
- data[type] = [{}]
440
+ if ((isFilter && !data[type].length) || data.isFilter)
441
+ data[type] = [{ isFilter: 'isEmptyObjectFilter' }];
442
+ // data[type].splice(0, 0, { isFilter: 'isEmptyObjectFilter' });
450
443
 
451
- let transactionType = "readwrite" //test
452
- if (data.method == 'read.object')
444
+ let transactionType = "readwrite"
445
+ if (data.method == 'object.read')
453
446
  transactionType = "readonly"
454
447
 
455
448
  let transaction = db.transaction([array], transactionType);
@@ -458,41 +451,37 @@ async function processObject(data, newData, database, array, type) {
458
451
  let globalOperators = getGlobalOperators(data)
459
452
  let upsert = data.upsert
460
453
 
461
- if (data.$filter) {
462
- let count = objectStore.count();
463
- count.onsuccess = function () {
464
- data.$filter.count = count.result
465
- }
466
- }
467
-
468
454
  for (let i = 0; i < data[type].length; i++) {
469
455
  delete data[type][i].$storage
470
456
  delete data[type][i].$database
471
457
  delete data[type][i].$array
472
458
 
473
- if (data.method == 'create.object') {
459
+ if (data.method == 'object.create') {
474
460
  if (data.organization_id)
475
461
  data[type][i]['organization_id'] = data.organization_id
476
462
 
477
463
  if (!data[type][i]._id)
478
464
  data[type][i]['_id'] = ObjectId().toString()
479
465
  data[type][i] = dotNotationToObject(data[type][i])
466
+
467
+ // TODO: user_id || clientId shohould be retrieved from CoCreate
480
468
  data[type][i]['created'] = { on: data.timeStamp, by: data.user_id || data.clientId }
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
481
473
 
482
- let result = await add(objectStore, data[type][i])
483
- newData.push({ $storage: 'indexeddb', $database: database, $array: array, ...result })
484
474
  } else {
485
475
  if (data[type][i].$filter)
486
476
  isFilter = true
487
- // if (data.organization_id)
488
- // data[type][i]['organization_id'] = data.organization_id
489
477
 
490
- if (data.method == 'update.object') {
478
+ if (data.method == 'object.update') {
491
479
  if (data.organization_id)
492
480
  data[type][i]['organization_id'] = data.organization_id
493
481
 
494
482
  if (data[type][i].$upsert)
495
483
  upsert = data[type][i].$upsert
484
+ // TODO: user_id || clientId shohould be retrieved from CoCreate
496
485
  data[type][i]['modified'] = { on: data.timeStamp, by: data.user_id || data.clientId }
497
486
  }
498
487
 
@@ -500,13 +489,6 @@ async function processObject(data, newData, database, array, type) {
500
489
  if (data[type][i]._id)
501
490
  range = IDBKeyRange.only(data[type][i]._id);
502
491
  else if (isFilter) {
503
- if (data.object.$filter) {
504
- let count = objectStore.count();
505
- count.onsuccess = function () {
506
- data.object.$filter.count = count.result
507
- }
508
- }
509
-
510
492
  let isIndex = false
511
493
  let indexName, direction;
512
494
 
@@ -545,22 +527,39 @@ async function processObject(data, newData, database, array, type) {
545
527
  let indexExist = indexNames.includes(indexName)
546
528
  if (!indexExist) {
547
529
  db.close()
548
- db = await processDatabase({ method: 'get.database', database, array, indexName, upgrade: true })
549
- objectStore = db.transaction(array, 'readwrite');
530
+ db = await processDatabase({ method: 'database.get', database, array, indexName })
531
+ transaction = db.transaction(array, 'readwrite');
550
532
  objectStore = transaction.objectStore(array);
551
533
  }
552
534
  objectStore = objectStore.index(indexName);
553
535
  }
554
536
 
537
+ let count = objectStore.count();
538
+ count.onsuccess = function () {
539
+ if (data.$filter)
540
+ data.$filter.count = count.result
541
+ else if (data.object.$filter)
542
+ data.object.$filter.count = count.result
543
+ }
544
+
555
545
  if (data.$filter) {
556
546
  if (data.$filter.index)
557
547
  index = data.$filter.index
558
548
  if (data.$filter.limit)
559
549
  limit = data.$filter.limit
560
- if (limit)
561
- limit = (index || 0) + limit;
562
550
  }
563
- } else if (data.method == 'delete.object' || data.method == 'update.object' && !range && !upsert && !isFilter) {
551
+
552
+ if (data[type][i].$filter) {
553
+ if (data[type][i].$filter.index)
554
+ index = data[type][i].$filter.index
555
+ if (data[type][i].$filter.limit)
556
+ limit = data[type][i].$filter.limit
557
+ }
558
+
559
+ if (limit)
560
+ limit = (index || 0) + limit;
561
+
562
+ } else if (data.method == 'object.delete' || data.method == 'object.update' && !range && !upsert && !isFilter) {
564
563
  continue
565
564
  }
566
565
 
@@ -587,18 +586,18 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
587
586
  return new Promise(async (resolve, reject) => {
588
587
  const request = objectStore.openCursor(range || null, direction);// next, prev
589
588
 
590
- let hasUpdated
589
+ let hasUpdated, matchedLength = 0
591
590
  request.onsuccess = async () => {
592
591
  let cursor = request.result
593
592
 
594
- if (data.method === 'create.object'
595
- || data.method === 'update.object'
593
+ if (data.method === 'object.create'
594
+ || data.method === 'object.update'
596
595
  && (!range && !isFilter && upsert || !cursor && upsert && !hasUpdated)) {
597
596
  let isMatch = true
598
597
  if (isFilter) {
599
598
  if (cursor)
600
599
  isMatch = filter(objectStore, data[type][i], data[type][i], cursor.value)
601
- else if (data.method === 'update.object' && !upsert)
600
+ else if (data.method === 'object.update' && !upsert)
602
601
  isMatch = false
603
602
  }
604
603
 
@@ -610,20 +609,19 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
610
609
  }
611
610
 
612
611
  let result
613
- if (data.method == 'create.object') {
614
- result = await add(objectStore, data[type][i])
615
- } else if (data.method == 'update.object') {
616
- let update
617
- if (cursor)
618
- update = createUpdate(cursor.value, data[type][i], globalOperators)
619
- else
620
- update = createUpdate({}, data[type][i], globalOperators)
612
+ if (data.method == 'object.create') {
613
+ data[type][i] = await add(objectStore, data[type][i])
614
+ } else if (data.method == 'object.update') {
615
+ let update = createUpdate((cursor && cursor.value) ? cursor.value : {}, data[type][i], globalOperators)
621
616
  if (update)
622
- result = await put(objectStore, update)
617
+ data[type][i] = await put(objectStore, update)
623
618
  }
619
+ data[type][i].$storage = 'indexeddb'
620
+ data[type][i].$database = database
621
+ data[type][i].$array = array
622
+
623
+ matchedLength++
624
624
 
625
- if (result)
626
- newData.push({ $storage: 'indexeddb', $database: database, $array: array, ...result })
627
625
  }
628
626
  resolve();
629
627
  } else if (cursor) {
@@ -634,7 +632,7 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
634
632
  if (isMatch !== false) {
635
633
  let result = cursor.value
636
634
 
637
- if (data.method == 'update.object') {
635
+ if (data.method == 'object.update') {
638
636
  let update = createUpdate(cursor.value, data[type][i], globalOperators)
639
637
  if (update)
640
638
  result = await put(objectStore, update)
@@ -643,15 +641,25 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
643
641
  // TODO: if update.$<operator>.someKey[] requires the index of inerted item added to the field name. update.$<operator>.someKey[<index>]
644
642
  // TODO: if $addToSet get field name and item if it does not exist.
645
643
  // TODO: if $pull get field name and find if item exist and delete.
646
- } else if (data.method == 'delete.object') {
644
+ } else if (data.method == 'object.delete') {
647
645
  result = cursor.value
648
646
  cursor.delete()
649
647
  }
650
648
 
651
- newData.push({ $storage: 'indexeddb', $database: database, $array: array, ...result })
649
+ if (data[type][i]._id)
650
+ data[type][i] = { $storage: 'indexeddb', $database: database, $array: array, ...result }
651
+ else {
652
+ let object = data[type].find(obj => obj._id && obj._id === result._id)
653
+ if (object)
654
+ object = { $storage: 'indexeddb', $database: database, $array: array, ...object, ...result }
655
+ else
656
+ newData.push({ $storage: 'indexeddb', $database: database, $array: array, ...result })
657
+ }
658
+
659
+ matchedLength++
652
660
  }
653
661
 
654
- if (!limit || limit && limit < newData.length) {
662
+ if (!limit || limit && (limit < newData.length || limit < matchedLength)) {
655
663
  cursor.continue();
656
664
  } else if (cursor.close) {
657
665
  cursor.close()
@@ -659,6 +667,7 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
659
667
  } else {
660
668
  resolve();
661
669
  }
670
+
662
671
  } else {
663
672
  resolve();
664
673
  }
@@ -711,15 +720,6 @@ function filter(objectStore, data, object, result) {
711
720
  let isMatch = true;
712
721
  let filter = data.$filter || object.$filter
713
722
  if (filter) {
714
- try {
715
- let count = objectStore.count();
716
- count.onsuccess = function () {
717
- filter.count = count.result
718
- }
719
- } catch (error) {
720
- errorHandler(data, error, database, array)
721
- }
722
-
723
723
  if (filter.query)
724
724
  isMatch = queryData(result, filter.query);
725
725
  if (isMatch && filter.search)
@@ -854,18 +854,17 @@ function dotNotationToObjectUpdate(data, object = {}) {
854
854
  }
855
855
 
856
856
  function createData(data, newData, type) {
857
- data.request = data[type] || {}
857
+ // data.request = data[type] || {}
858
+ if (data[type] && data[type][0] && data[type][0].isFilter === 'isEmptyObjectFilter') {
859
+ data[type].shift()
860
+ data.isFilter = true
861
+ }
862
+
863
+ data[type].push(...newData)
858
864
 
859
865
  if (data.$filter && data.$filter.sort)
860
- data[type] = sortData(newData, data.$filter.sort)
861
- else
862
- data[type] = newData
866
+ data[type] = sortData(data[type], data.$filter.sort)
863
867
 
864
- if (data.returnLog) {
865
- if (!data.log)
866
- data.log = []
867
- data.log.push(...data[type])
868
- }
869
868
 
870
869
  return data
871
870
  }
@@ -1,37 +1,37 @@
1
- async function testCollections() {
1
+ async function testArrays() {
2
2
  if (!('indexedDB' in window)) {
3
3
  console.log("This browser doesn't support IndexedDB.");
4
4
  return;
5
5
  } else {
6
6
 
7
- let createCollection = await CoCreate.indexeddb.process({
8
- method: 'create.array',
9
- database: ['testDB', 'testDB1', 'testDB2'],
10
- array: ['testCollection', 'testCollection1', 'testCollection2']
7
+ let createObject = await CoCreate.indexeddb.process({
8
+ method: 'array.create',
9
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
10
+ array: ['testArray', 'testArray1', 'testArray2']
11
11
 
12
12
  })
13
- console.log('createCollection', createCollection)
13
+ console.log('createObject', createObject)
14
14
 
15
- let readCollection = await CoCreate.indexeddb.process({
16
- method: 'read.array',
17
- database: ['testDB', 'testDB1', 'testDB2'],
15
+ let readObject = await CoCreate.indexeddb.process({
16
+ method: 'array.read',
17
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
18
18
  })
19
- console.log('readCollection', readCollection)
19
+ console.log('readObject', readObject)
20
20
 
21
- let updateCollection = await CoCreate.indexeddb.process({
22
- method: 'update.array',
23
- database: ['testDB', 'testDB1', 'testDB2'],
24
- array: { testCollection: 'testCollectionA' }
21
+ let updateObject = await CoCreate.indexeddb.process({
22
+ method: 'array.update',
23
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
24
+ array: { testArray: 'testArrayA' }
25
25
  })
26
- console.log('updateCollection', updateCollection)
26
+ console.log('updateObject', updateObject)
27
27
 
28
28
 
29
- let deleteCollection = await CoCreate.indexeddb.process({
30
- method: 'delete.array',
31
- database: ['testDB', 'testDB1', 'testDB2'],
32
- array: ['testCollectionA', 'testCollection1', 'testCollection2']
29
+ let deleteObject = await CoCreate.indexeddb.process({
30
+ method: 'array.delete',
31
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
32
+ array: ['testArrayA', 'testArray1', 'testArray2']
33
33
  })
34
- console.log('deleteCollection', deleteCollection)
34
+ console.log('deleteObject', deleteObject)
35
35
 
36
36
  }
37
37
  }
package/test/databases.js CHANGED
@@ -4,26 +4,26 @@ async function testDatabases() {
4
4
  return;
5
5
  } else {
6
6
  let createDatabase = await CoCreate.indexeddb.process({
7
- method: 'create.database',
7
+ method: 'database.create',
8
8
  database: 'testDB',
9
9
  })
10
10
  console.log('createDatabase', createDatabase)
11
11
 
12
12
  let readDatabase = await CoCreate.indexeddb.process({
13
- method: 'read.database',
13
+ method: 'database.read',
14
14
  database: 'testDB',
15
15
  })
16
16
  console.log('readDatabase', readDatabase)
17
17
 
18
18
  let updateDatabase = await CoCreate.indexeddb.process({
19
- method: 'update.database',
19
+ method: 'database.update',
20
20
  database: { testDB: 'testDatabase1' }
21
21
  })
22
22
  console.log('updateDatabase', updateDatabase)
23
23
 
24
24
 
25
25
  let deleteDatabase = await CoCreate.indexeddb.process({
26
- method: 'delete.database',
26
+ method: 'database.delete',
27
27
  database: ['testDB', 'testDB1', 'testDB2'],
28
28
  })
29
29
  console.log('deleteDatabase', deleteDatabase)
package/test/documents.js CHANGED
@@ -1,13 +1,13 @@
1
1
  async function testDocuments() {
2
- if (!('indexedDB' in window)) {
3
- console.log("This browser doesn't support IndexedDB.");
2
+ if (!('indexedDatabase' in window)) {
3
+ console.log("This browser doesn't support IndexedDatabase.");
4
4
  return;
5
5
  } else {
6
6
 
7
- let createDocument = await CoCreate.indexeddb.process({
8
- method: 'create.object',
9
- database: ['testDB', 'testDB1', 'testDB2'],
10
- array: ['testCollection', 'testCollection1', 'testCollection2'],
7
+ let createObject = await CoCreate.indexeddb.process({
8
+ method: 'object.create',
9
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
10
+ array: ['testArray', 'testArray1', 'testArray2'],
11
11
  object: {
12
12
  organization_id: '5ff747727005da1c272740ab',
13
13
  'books.action.title': 'matr',
@@ -15,24 +15,24 @@ async function testDocuments() {
15
15
  }
16
16
 
17
17
  })
18
- console.log('createDocument', createDocument)
19
- let _id = createDocument.object[0]._id
18
+ console.log('createObject', createObject)
19
+ let _id = createObject.object[0]._id
20
20
 
21
- let readDocument = await CoCreate.indexeddb.process({
22
- method: 'read.object',
23
- database: ['testDB', 'testDB1', 'testDB2'],
24
- array: ['testCollection', 'testCollection1', 'testCollection2'],
21
+ let readObject = await CoCreate.indexeddb.process({
22
+ method: 'object.read',
23
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
24
+ array: ['testArray', 'testArray1', 'testArray2'],
25
25
  object: {
26
26
  _id,
27
27
  }
28
28
 
29
29
  })
30
- console.log('readDocument', readDocument)
30
+ console.log('readObject', readObject)
31
31
 
32
- let updateDocument = await CoCreate.indexeddb.process({
33
- method: 'update.object',
34
- database: ['testDB', 'testDB1', 'testDB2'],
35
- array: ['testCollection', 'testCollection1', 'testCollection2'],
32
+ let updateObject = await CoCreate.indexeddb.process({
33
+ method: 'object.update',
34
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
35
+ array: ['testArray', 'testArray1', 'testArray2'],
36
36
  object: {
37
37
  _id,
38
38
  'books.action.title': 'matr',
@@ -40,13 +40,13 @@ async function testDocuments() {
40
40
  }
41
41
 
42
42
  })
43
- console.log('updateDocument', updateDocument)
43
+ console.log('updateObject', updateObject)
44
44
 
45
45
 
46
- let deleteDocument = await CoCreate.indexeddb.process({
47
- method: 'delete.object',
48
- database: ['testDB', 'testDB1', 'testDB2'],
49
- array: ['testCollection', 'testCollection1', 'testCollection2'],
46
+ let deleteObject = await CoCreate.indexeddb.process({
47
+ method: 'object.delete',
48
+ database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
49
+ array: ['testArray', 'testArray1', 'testArray2'],
50
50
  // object: {
51
51
  // _id
52
52
  // }
@@ -58,10 +58,10 @@ async function testDocuments() {
58
58
 
59
59
 
60
60
  })
61
- console.log('deleteDocument', deleteDocument)
61
+ console.log('deleteObject', deleteObject)
62
62
 
63
63
  // let deleteDatabase = await CoCreate.indexeddb.deleteDatabase({
64
- // database: ['testDB', 'testDB1', 'testDB2'],
64
+ // database: ['testDatabase', 'testDatabase1', 'testDatabase2'],
65
65
  // })
66
66
  // console.log('deleteDatabase', deleteDatabase)
67
67
  }
package/test/index.html CHANGED
@@ -6,9 +6,9 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
7
7
  <link
8
8
  rel="icon"
9
- href="https://cdn.cocreate.app/favicon.ico"
10
- type="image/ico"
11
- sizes="16x16" />
9
+ type="image/png"
10
+ sizes="32x32"
11
+ href="../assets/favicon.ico" />
12
12
  <title>indexeddb | CoCreateJS</title>
13
13
  <link rel="manifest" href="/manifest.webmanifest" />
14
14
  </head>