@cocreate/mongodb 1.4.18 → 1.6.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,25 @@
1
+ # [1.6.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.5.0...v1.6.0) (2023-08-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * bump cocreate dependencies for the latest updates and features ([3cb3e3d](https://github.com/CoCreate-app/CoCreate-mongodb/commit/3cb3e3d054ff634abcdd2531de42d7492c45a551))
7
+
8
+ # [1.5.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.4.18...v1.5.0) (2023-08-16)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * crud attributes renamed ([08ecbf2](https://github.com/CoCreate-app/CoCreate-mongodb/commit/08ecbf218203a2d08dad7ac298aa8b4feeb09452))
14
+ * Refactored *-target to *-selector ([9fa3212](https://github.com/CoCreate-app/CoCreate-mongodb/commit/9fa3212a4994c08b58c978620ed3f763ba8ea8db))
15
+ * startIndex variable renamed to index and comment out unnecessary code. ([b20bf7a](https://github.com/CoCreate-app/CoCreate-mongodb/commit/b20bf7a1beae3345e64af432c9651e686b78690f))
16
+ * webpack.config and package.json make use of mode=production instead of process.env ([22a2454](https://github.com/CoCreate-app/CoCreate-mongodb/commit/22a24544bc29be1d83cb6acae750619a6b14cdb3))
17
+
18
+
19
+ ### Features
20
+
21
+ * name attribute and variable renamed to key ([79e1c03](https://github.com/CoCreate-app/CoCreate-mongodb/commit/79e1c039924b2a013d8c2de2e83eb807443e0d65))
22
+
1
23
  ## [1.4.18](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.4.17...v1.4.18) (2023-06-14)
2
24
 
3
25
 
@@ -4,8 +4,8 @@ module.exports = {
4
4
  "host": "",
5
5
 
6
6
  "sources": [{
7
- "collection": "files",
8
- "document": {
7
+ "array": "files",
8
+ "object": {
9
9
  "_id": "60145dc49f64ba1680b86693",
10
10
  "name": "index.html",
11
11
  "path": "/docs/mongodb/index.html",
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
- name="description"
14
+ key="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
16
  <meta
17
- name="keywords"
17
+ key="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
 
@@ -26,7 +26,7 @@
26
26
  </head>
27
27
 
28
28
  <body>
29
- <div collection="" document_id="" name="" id="cocreate-mongodb">
29
+ <div array="" object="" key="" id="cocreate-mongodb">
30
30
  <div
31
31
  class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
32
32
  <div class="display:flex align-items:center">
@@ -157,9 +157,9 @@
157
157
  <textarea
158
158
  type="code"
159
159
  lang="html"
160
- collection="demos"
161
- document_id=""
162
- name="demo"
160
+ array="demos"
161
+ object=""
162
+ key="demo"
163
163
  save="false"
164
164
  id="demo"
165
165
  class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
@@ -184,7 +184,7 @@
184
184
  show="#eye-slash"
185
185
  hide="#eye, #demo-preview"
186
186
  toggle="code-height"
187
- toggle-target="#demo-code"
187
+ toggle-selector="#demo-code"
188
188
  ><i class="far fa-eye"></i
189
189
  ></a>
190
190
  <a
@@ -194,7 +194,7 @@
194
194
  show="#eye, #demo-preview"
195
195
  hide="#eye-slash"
196
196
  toggle="code-height"
197
- toggle-target="#demo-code"
197
+ toggle-selector="#demo-code"
198
198
  ><i class="fas fa-eye-slash"></i
199
199
  ></a>
200
200
  <a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.4.18",
3
+ "version": "1.6.0",
4
4
  "description": "A simple mongodb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "mongodb",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "start": "npx webpack --config webpack.config.js",
28
- "build": "NODE_ENV=production npx webpack --config webpack.config.js",
28
+ "build": "npx webpack --mode=production --config webpack.config.js",
29
29
  "dev": "npx webpack --config webpack.config.js --watch",
30
30
  "postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
31
31
  },
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "dependencies": {
48
- "@cocreate/utils": "^1.21.15",
48
+ "@cocreate/utils": "^1.22.0",
49
49
  "mongodb": "^4.12.1"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -89,32 +89,32 @@ function database(action, data) {
89
89
 
90
90
 
91
91
  function createCollection(data) {
92
- return collection('createCollection', data)
92
+ return array('createCollection', data)
93
93
  }
94
94
 
95
95
  function readCollection(data) {
96
- return collection('readCollection', data)
96
+ return array('readCollection', data)
97
97
  }
98
98
 
99
99
  function updateCollection(data) {
100
- return collection('updateCollection', data)
100
+ return array('updateCollection', data)
101
101
  }
102
102
 
103
103
  function deleteCollection(data) {
104
- return collection('deleteCollection', data)
104
+ return array('deleteCollection', data)
105
105
  }
106
106
 
107
- function collection(action, data) {
107
+ function array(action, data) {
108
108
  return new Promise(async (resolve, reject) => {
109
- let type = 'collection'
110
- let collectionArray = [];
109
+ let type = 'array'
110
+ let arrayArray = [];
111
111
 
112
112
  try {
113
113
  const client = await dbClient(data)
114
114
  if (!client) return
115
115
 
116
116
  if (data.request)
117
- data.collection = data.request
117
+ data.array = data.request
118
118
 
119
119
  let databases = data.database;
120
120
  if (!Array.isArray(databases))
@@ -137,70 +137,70 @@ function collection(action, data) {
137
137
  if (data.filter && data.filter.query) {
138
138
  let isFilter = queryData(res, data.filter.query)
139
139
  if (isFilter)
140
- collectionArray.push({ name: res.name, database, db: 'mongodb' })
140
+ arrayArray.push({ name: res.name, database, db: 'mongodb' })
141
141
  } else
142
- collectionArray.push({ name: res.name, database, db: 'mongodb' })
142
+ arrayArray.push({ name: res.name, database, db: 'mongodb' })
143
143
  }
144
144
  }
145
145
 
146
146
  databasesLength -= 1
147
147
  if (!databasesLength) {
148
- data = createData(data, collectionArray, type)
148
+ data = createData(data, arrayArray, type)
149
149
  resolve(data)
150
150
  }
151
151
  })
152
152
  } else {
153
- let collections
153
+ let arrays
154
154
  let value
155
155
  if (action == 'updateCollection')
156
- collections = Object.entries(data.collection)
156
+ arrays = Object.entries(data.array)
157
157
  else
158
- collections = data.collection;
158
+ arrays = data.array;
159
159
 
160
- if (!Array.isArray(collections))
161
- collections = [collections]
160
+ if (!Array.isArray(arrays))
161
+ arrays = [arrays]
162
162
 
163
- let collectionsLength = collections.length
164
- for (let collection of collections) {
163
+ let arraysLength = arrays.length
164
+ for (let array of arrays) {
165
165
 
166
166
  if (action == 'createCollection') {
167
- db.createCollection(collection, function (error, result) {
167
+ db.createCollection(array, function (error, result) {
168
168
  if (error)
169
- errorHandler(data, error, database, collection)
169
+ errorHandler(data, error, database, array)
170
170
 
171
171
  if (result)
172
- collectionArray.push({ name: collection, database, db: 'mongodb' })
172
+ arrayArray.push({ name: array, database, db: 'mongodb' })
173
173
 
174
- collectionsLength -= 1
175
- if (!collectionsLength)
174
+ arraysLength -= 1
175
+ if (!arraysLength)
176
176
  databasesLength -= 1
177
177
 
178
- if (!databasesLength && !collectionsLength) {
179
- data = createData(data, collectionArray, type)
178
+ if (!databasesLength && !arraysLength) {
179
+ data = createData(data, arrayArray, type)
180
180
  resolve(data)
181
181
  }
182
182
  })
183
183
  } else {
184
184
  if (action == 'updateCollection') {
185
- [collection, value] = collection
185
+ [array, value] = array
186
186
  }
187
187
 
188
- const collectionObj = db.collection(collection);
188
+ const arrayObj = db.array(array);
189
189
 
190
190
  if (action == 'updateCollection') {
191
- collectionObj.rename(value, function (error, result) {
191
+ arrayObj.rename(value, function (error, result) {
192
192
  if (error)
193
- errorHandler(data, error, database, collection)
193
+ errorHandler(data, error, database, array)
194
194
 
195
195
  if (result)
196
- collectionArray.push({ name: value, oldName: collection, database, db: 'mongodb' })
196
+ arrayArray.push({ name: value, oldName: array, database, db: 'mongodb' })
197
197
 
198
- collectionsLength -= 1
199
- if (!collectionsLength)
198
+ arraysLength -= 1
199
+ if (!arraysLength)
200
200
  databasesLength -= 1
201
201
 
202
- if (!databasesLength && !collectionsLength) {
203
- data = createData(data, collectionArray, type)
202
+ if (!databasesLength && !arraysLength) {
203
+ data = createData(data, arrayArray, type)
204
204
  resolve(data)
205
205
  }
206
206
 
@@ -208,19 +208,19 @@ function collection(action, data) {
208
208
  }
209
209
 
210
210
  if (action == 'deleteCollection') {
211
- collectionObj.drop(function (error, result) {
211
+ arrayObj.drop(function (error, result) {
212
212
  if (error)
213
- errorHandler(data, error, database, collection)
213
+ errorHandler(data, error, database, array)
214
214
 
215
215
  if (result)
216
- collectionArray.push({ name: collection, database, db: 'mongodb' })
216
+ arrayArray.push({ name: array, database, db: 'mongodb' })
217
217
 
218
- collectionsLength -= 1
219
- if (!collectionsLength)
218
+ arraysLength -= 1
219
+ if (!arraysLength)
220
220
  databasesLength -= 1
221
221
 
222
- if (!databasesLength && !collectionsLength) {
223
- data = createData(data, collectionArray, type)
222
+ if (!databasesLength && !arraysLength) {
223
+ data = createData(data, arrayArray, type)
224
224
  resolve(data)
225
225
  }
226
226
 
@@ -244,20 +244,20 @@ function collection(action, data) {
244
244
  }
245
245
 
246
246
 
247
- function createDocument(data) {
248
- return document('createDocument', data)
247
+ function createObject(data) {
248
+ return document('createObject', data)
249
249
  }
250
250
 
251
- function readDocument(data) {
252
- return document('readDocument', data)
251
+ function readObject(data) {
252
+ return document('readObject', data)
253
253
  }
254
254
 
255
- function updateDocument(data) {
256
- return document('updateDocument', data)
255
+ function updateObject(data) {
256
+ return document('updateObject', data)
257
257
  }
258
258
 
259
- function deleteDocument(data) {
260
- return document('deleteDocument', data)
259
+ function deleteObject(data) {
260
+ return document('deleteObject', data)
261
261
  }
262
262
 
263
263
  function document(action, data) {
@@ -287,14 +287,14 @@ function document(action, data) {
287
287
 
288
288
  let databasesLength = databases.length
289
289
  for (let database of databases) {
290
- let collections = data.collection;
291
- if (!Array.isArray(collections))
292
- collections = [collections]
290
+ let arrays = data.array;
291
+ if (!Array.isArray(arrays))
292
+ arrays = [arrays]
293
293
 
294
- let collectionsLength = collections.length
295
- for (let collection of collections) {
294
+ let arraysLength = arrays.length
295
+ for (let array of arrays) {
296
296
  const db = client.db(database);
297
- const collectionObj = db.collection(collection);
297
+ const arrayObj = db.array(array);
298
298
 
299
299
  let { query, sort } = getFilters(data);
300
300
  if (data['organization_id']) {
@@ -313,7 +313,7 @@ function document(action, data) {
313
313
  data[type][i]['organization_id'] = data['organization_id'];
314
314
 
315
315
 
316
- if (action == 'createDocument') {
316
+ if (action == 'createObject') {
317
317
  data[type][i] = dotNotationToObject(data[type][i])
318
318
 
319
319
  if (!data[type][i]._id)
@@ -322,10 +322,10 @@ function document(action, data) {
322
322
  data[type][i]._id = ObjectId(data[type][i]._id)
323
323
  data[type][i]['created'] = { on: data.timeStamp, by: data.user_id || data.clientId }
324
324
  }
325
- if (action == 'readDocument' && data[type][i]._id) {
325
+ if (action == 'readObject' && data[type][i]._id) {
326
326
  _ids.push(ObjectId(data[type][i]._id))
327
327
  }
328
- if (action == 'updateDocument') {
328
+ if (action == 'updateObject') {
329
329
  if (data[type][i]._id)
330
330
  update_ids.push({ _id: data[type][i]._id, updateDoc: data[type][i], updateType: '_id' })
331
331
 
@@ -335,10 +335,10 @@ function document(action, data) {
335
335
  data[type][i]['modified'] = { on: data.timeStamp, by: data.user_id || data.clientId }
336
336
 
337
337
  }
338
- if (action == 'deleteDocument') {
338
+ if (action == 'deleteObject') {
339
339
  if (data[type][i]._id) {
340
340
  _ids.push(ObjectId(data[type][i]._id))
341
- documents.push({ _id: data[type][i]._id, db: 'mongodb', database, collection })
341
+ documents.push({ _id: data[type][i]._id, db: 'mongodb', database, array })
342
342
  }
343
343
  }
344
344
  }
@@ -349,42 +349,42 @@ function document(action, data) {
349
349
  }
350
350
 
351
351
 
352
- if (action == 'createDocument') {
353
- collectionObj.insertMany(data[type], function (error, result) {
352
+ if (action == 'createObject') {
353
+ arrayObj.insertMany(data[type], function (error, result) {
354
354
  if (error)
355
- errorHandler(data, error, database, collection)
355
+ errorHandler(data, error, database, array)
356
356
 
357
357
  for (let i = 0; i < data[type].length; i++)
358
- documents.push({ db: 'mongodb', database, collection, ...data[type][i] })
358
+ documents.push({ db: 'mongodb', database, array, ...data[type][i] })
359
359
 
360
- collectionsLength -= 1
361
- if (!collectionsLength)
360
+ arraysLength -= 1
361
+ if (!arraysLength)
362
362
  databasesLength -= 1
363
363
 
364
- if (!databasesLength && !collectionsLength) {
364
+ if (!databasesLength && !arraysLength) {
365
365
  data = createData(data, documents, type)
366
366
  resolve(data)
367
367
  }
368
368
  });
369
369
  }
370
370
 
371
- if (action == 'readDocument') {
371
+ if (action == 'readObject') {
372
372
  let index = 0, limit = 0
373
373
  if (data.filter) {
374
- const count = await collectionObj.estimatedDocumentCount()
374
+ const count = await arrayObj.estimatedDocumentCount()
375
375
  data.filter.count = count
376
376
 
377
- if (data.filter.startIndex)
378
- index = data.filter.startIndex
377
+ if (data.filter.index)
378
+ index = data.filter.index
379
379
  if (data.filter.limit)
380
380
  limit = data.filter.limit
381
381
  if (limit)
382
382
  limit = index + limit;
383
383
  }
384
384
 
385
- collectionObj.find(query).limit(limit).sort(sort).toArray(function (error, result) {
385
+ arrayObj.find(query).skip(index).limit(limit).sort(sort).toArray(function (error, result) {
386
386
  if (error)
387
- errorHandler(data, error, database, collection)
387
+ errorHandler(data, error, database, array)
388
388
 
389
389
  if (result) {
390
390
  // TODO: forEach at cursor
@@ -395,10 +395,10 @@ function document(action, data) {
395
395
  if (isMatch) {
396
396
  doc.storage = 'mongodb'
397
397
  doc.database = database
398
- doc.collection = collection
398
+ doc.array = array
399
399
  doc._id = doc._id.toString()
400
400
 
401
- if (data.returnDocument == false) {
401
+ if (data.returnObject == false) {
402
402
  let tempDoc = {};
403
403
  let docs = new Map(data[type].map((obj) => [obj._id, obj]));
404
404
  let doc1 = docs.get(doc._id)
@@ -415,29 +415,29 @@ function document(action, data) {
415
415
  }
416
416
  }
417
417
 
418
- if (index && limit) {
419
- documents = documents.slice(index, limit)
420
- }
418
+ // if (index && limit) {
419
+ // documents = documents.slice(index, limit)
420
+ // }
421
421
  }
422
422
 
423
- collectionsLength -= 1
424
- if (!collectionsLength)
423
+ arraysLength -= 1
424
+ if (!arraysLength)
425
425
  databasesLength -= 1
426
426
 
427
- if (!databasesLength && !collectionsLength) {
427
+ if (!databasesLength && !arraysLength) {
428
428
  data = createData(data, documents, type)
429
429
  resolve(data)
430
430
  }
431
431
  });
432
432
  }
433
433
 
434
- if (action == 'updateDocument' || action == 'deleteDocument') {
434
+ if (action == 'updateObject' || action == 'deleteObject') {
435
435
  const queryDocs = () => {
436
436
  return new Promise(async (resolve, reject) => {
437
437
 
438
- collectionObj.find(query).sort(sort).toArray(function (error, result) {
438
+ arrayObj.find(query).sort(sort).toArray(function (error, result) {
439
439
  if (error)
440
- errorHandler(data, error, database, collection)
440
+ errorHandler(data, error, database, array)
441
441
 
442
442
  if (data.filter && data.filter.search) {
443
443
  let searchResult = []
@@ -458,14 +458,14 @@ function document(action, data) {
458
458
 
459
459
  let Result, $update, update, projection;
460
460
 
461
- if (isFilter && data.returnDocument != false)
462
- if (action == 'deleteDocument' || action == 'updateDocument' && updateData.update)
461
+ if (isFilter && data.returnObject != false)
462
+ if (action == 'deleteObject' || action == 'updateObject' && updateData.update)
463
463
  Result = await queryDocs()
464
464
 
465
465
  if (Result) {
466
466
  for (let doc of Result) {
467
- if (action == 'deleteDocument')
468
- documents.push({ _id: doc._id, db: 'mongodb', database, collection })
467
+ if (action == 'deleteObject')
468
+ documents.push({ _id: doc._id, db: 'mongodb', database, array })
469
469
  else
470
470
  doc['modified'] = { on: data.timeStamp, by: data.user_id || data.clientId }
471
471
 
@@ -474,7 +474,7 @@ function document(action, data) {
474
474
  update_ids.push({ updateType: 'filter' })
475
475
  }
476
476
 
477
- if (action == 'updateDocument') {
477
+ if (action == 'updateObject') {
478
478
  let docsLength = update_ids.length
479
479
  for (let { updateDoc, updateType } of update_ids) {
480
480
 
@@ -484,7 +484,7 @@ function document(action, data) {
484
484
  $update = createUpdate({ document: [updateDoc] }, type)
485
485
  update = $update.update
486
486
  projection = $update.projection
487
- documents.push({ _id: update_id, db: 'mongodb', database, collection, ...update['$set'] })
487
+ documents.push({ _id: update_id, db: 'mongodb', database, array, ...update['$set'] })
488
488
  }
489
489
 
490
490
  if (updateType == 'filter') {
@@ -493,29 +493,29 @@ function document(action, data) {
493
493
  update = $update.update
494
494
  projection = $update.projection
495
495
  for (let _id of _ids)
496
- documents.push({ _id, db: 'mongodb', database, collection, ...update['$set'] })
496
+ documents.push({ _id, db: 'mongodb', database, array, ...update['$set'] })
497
497
 
498
498
  }
499
499
 
500
500
  update['$set']['organization_id'] = data.organization_id
501
501
 
502
- collectionObj.updateMany(query, update, {
502
+ arrayObj.updateMany(query, update, {
503
503
  upsert: data.upsert,
504
504
  projection
505
505
  }).then((result) => {
506
506
 
507
507
  }).catch((error) => {
508
- errorHandler(data, error, database, collection)
508
+ errorHandler(data, error, database, array)
509
509
  console.log(action, 'error', error);
510
510
  }).finally((error) => {
511
511
  docsLength -= 1
512
512
  if (!docsLength)
513
- collectionsLength -= 1
513
+ arraysLength -= 1
514
514
 
515
- if (!collectionsLength)
515
+ if (!arraysLength)
516
516
  databasesLength -= 1
517
517
 
518
- if (!databasesLength && !collectionsLength) {
518
+ if (!databasesLength && !arraysLength) {
519
519
  data = createData(data, documents, type)
520
520
  resolve(data)
521
521
  }
@@ -525,12 +525,12 @@ function document(action, data) {
525
525
  if (!update_ids.length) {
526
526
  docsLength -= 1
527
527
  if (!docsLength)
528
- collectionsLength -= 1
528
+ arraysLength -= 1
529
529
 
530
- if (!collectionsLength)
530
+ if (!arraysLength)
531
531
  databasesLength -= 1
532
532
 
533
- if (!databasesLength && !collectionsLength) {
533
+ if (!databasesLength && !arraysLength) {
534
534
  data = createData(data, documents, type)
535
535
  resolve(data)
536
536
  }
@@ -538,17 +538,17 @@ function document(action, data) {
538
538
 
539
539
  }
540
540
 
541
- if (action == 'deleteDocument') {
541
+ if (action == 'deleteObject') {
542
542
  if (_ids.length == 1)
543
543
  query['_id'] = ObjectId(_ids[0])
544
544
  else if (_ids.length > 0)
545
545
  query['_id'] = { $in: _ids }
546
- collectionObj.deleteMany(query, function (error, result) {
547
- collectionsLength -= 1
548
- if (!collectionsLength)
546
+ arrayObj.deleteMany(query, function (error, result) {
547
+ arraysLength -= 1
548
+ if (!arraysLength)
549
549
  databasesLength -= 1
550
550
 
551
- if (!databasesLength && !collectionsLength) {
551
+ if (!databasesLength && !arraysLength) {
552
552
  data = createData(data, documents, type)
553
553
  resolve(data)
554
554
  }
@@ -649,7 +649,7 @@ function getFilters(data) {
649
649
  value: [],
650
650
  type: "or"
651
651
  },
652
- startIndex: 0,
652
+ index: 0,
653
653
  ...data.filter
654
654
  };
655
655
 
@@ -664,7 +664,7 @@ function getFilters(data) {
664
664
  else
665
665
  direction = 1;
666
666
 
667
- sort[filter.sort[i].name] = filter.sort[i].direction
667
+ sort[filter.sort[i].key] = filter.sort[i].direction
668
668
  }
669
669
  }
670
670
  return { query, sort }
@@ -677,17 +677,17 @@ function createQuery(filters) {
677
677
 
678
678
  for (let item of filters) {
679
679
 
680
- if (!item.name)
680
+ if (!item.key)
681
681
  continue
682
682
 
683
- if (item.name == "_id") {
683
+ if (item.key == "_id") {
684
684
  if (item.value)
685
685
  item.value = ObjectId(item.value)
686
686
  else
687
687
  continue
688
688
  }
689
689
 
690
- let key = item.name;
690
+ let key = item.key;
691
691
  if (!query[key]) {
692
692
  query[key] = {};
693
693
  }
@@ -750,7 +750,7 @@ function createQuery(filters) {
750
750
  return query;
751
751
  }
752
752
 
753
- function errorHandler(data, error, database, collection) {
753
+ function errorHandler(data, error, database, array) {
754
754
  if (typeof error == 'object')
755
755
  error['storage'] = 'mongodb'
756
756
  else
@@ -758,8 +758,8 @@ function errorHandler(data, error, database, collection) {
758
758
 
759
759
  if (database)
760
760
  error['database'] = database
761
- if (collection)
762
- error['collection'] = collection
761
+ if (array)
762
+ error['array'] = array
763
763
  if (data.error)
764
764
  data.error.push(error)
765
765
  else
@@ -798,8 +798,8 @@ module.exports = {
798
798
  updateCollection,
799
799
  deleteCollection,
800
800
 
801
- createDocument,
802
- readDocument,
803
- updateDocument,
804
- deleteDocument,
801
+ createObject,
802
+ readObject,
803
+ updateObject,
804
+ deleteObject,
805
805
  }
package/webpack.config.js CHANGED
@@ -1,84 +1,90 @@
1
1
  const path = require("path")
2
2
  const TerserPlugin = require("terser-webpack-plugin")
3
3
  const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
- let isProduction = process.env.NODE_ENV === "production"
5
4
  const { CleanWebpackPlugin } = require("clean-webpack-plugin")
6
5
 
7
- module.exports = {
8
- entry: {
9
- "CoCreate-mongodb": "./src/index.js",
10
- },
11
- output: {
12
- path: path.resolve(__dirname, "dist"),
13
- filename: isProduction ? "[name].min.js" : "[name].js",
14
- libraryTarget: "umd",
15
- libraryExport: "default",
16
- library: ["CoCreate", "mongodb"],
17
- globalObject: "this",
18
- },
6
+ module.exports = (env, argv) => {
7
+ let isProduction = false
8
+ if (argv.mode === 'production')
9
+ isProduction = true
19
10
 
20
- plugins: [
21
- new CleanWebpackPlugin(),
22
- new MiniCssExtractPlugin({
23
- filename: "[name].css",
24
- }),
25
- ],
26
- // Default mode for Webpack is production.
27
- // Depending on mode Webpack will apply different things
28
- // on final bundle. For now we don't need production's JavaScript
29
- // minifying and other thing so let's set mode to development
30
- mode: isProduction ? "production" : "development",
31
- module: {
32
- rules: [
33
- {
34
- test: /.js$/,
35
- exclude: /(node_modules)/,
36
- use: {
37
- loader: "babel-loader",
38
- options: {
39
- plugins: ["@babel/plugin-transform-modules-commonjs"],
40
- },
11
+ const config = {
12
+ entry: {
13
+ "CoCreate-mongodb": "./src/index.js",
41
14
  },
42
- },
43
- {
44
- test: /.css$/i,
45
- use: [
46
- { loader: "style-loader", options: { injectType: "linkTag" } },
47
- "file-loader",
15
+ output: {
16
+ path: path.resolve(__dirname, "dist"),
17
+ filename: isProduction ? "[name].min.js" : "[name].js",
18
+ libraryTarget: "umd",
19
+ libraryExport: "default",
20
+ library: ["CoCreate", "mongodb"],
21
+ globalObject: "this",
22
+ },
23
+
24
+ plugins: [
25
+ new CleanWebpackPlugin(),
26
+ new MiniCssExtractPlugin({
27
+ filename: "[name].css",
28
+ }),
48
29
  ],
49
- },
50
- ],
51
- },
30
+ // Default mode for Webpack is production.
31
+ // Depending on mode Webpack will apply different things
32
+ // on final bundle. For now we don't need production's JavaScript
33
+ // minifying and other thing so let's set mode to development
34
+ mode: isProduction ? "production" : "development",
35
+ module: {
36
+ rules: [
37
+ {
38
+ test: /.js$/,
39
+ exclude: /(node_modules)/,
40
+ use: {
41
+ loader: "babel-loader",
42
+ options: {
43
+ plugins: ["@babel/plugin-transform-modules-commonjs"],
44
+ },
45
+ },
46
+ },
47
+ {
48
+ test: /.css$/i,
49
+ use: [
50
+ { loader: "style-loader", options: { injectType: "linkTag" } },
51
+ "file-loader",
52
+ ],
53
+ },
54
+ ],
55
+ },
52
56
 
53
- // add source map
54
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
57
+ // add source map
58
+ ...(isProduction ? {} : { devtool: "eval-source-map" }),
55
59
 
56
- optimization: {
57
- minimize: true,
58
- minimizer: [
59
- new TerserPlugin({
60
- extractComments: true,
61
- // cache: true,
62
- parallel: true,
63
- // sourceMap: true, // Must be set to true if using source-maps in production
64
- terserOptions: {
65
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
66
- // extractComments: 'all',
67
- compress: {
68
- drop_console: true,
69
- },
70
- },
71
- }),
72
- ],
73
- splitChunks: {
74
- chunks: "all",
75
- minSize: 200,
76
- // maxSize: 99999,
77
- //minChunks: 1,
60
+ optimization: {
61
+ minimize: true,
62
+ minimizer: [
63
+ new TerserPlugin({
64
+ extractComments: true,
65
+ // cache: true,
66
+ parallel: true,
67
+ // sourceMap: true, // Must be set to true if using source-maps in production
68
+ terserOptions: {
69
+ // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
70
+ // extractComments: 'all',
71
+ compress: {
72
+ drop_console: true,
73
+ },
74
+ },
75
+ }),
76
+ ],
77
+ splitChunks: {
78
+ chunks: "all",
79
+ minSize: 200,
80
+ // maxSize: 99999,
81
+ //minChunks: 1,
78
82
 
79
- cacheGroups: {
80
- defaultVendors: false,
81
- },
82
- },
83
- },
84
- }
83
+ cacheGroups: {
84
+ defaultVendors: false,
85
+ },
86
+ },
87
+ },
88
+ }
89
+ return config
90
+ }