liekodb 0.1.2 → 0.1.4

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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/liekodb.js +49 -49
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # LiekoDB Documentation
2
2
 
3
+ Online documentation
4
+ [LiekoDB Documentation](https://db.lieko.app/)
5
+
6
+
3
7
  ## Table of Contents
4
8
  1. [Introduction](#introduction)
5
9
  2. [Installation](#installation)
package/liekodb.js CHANGED
@@ -922,6 +922,36 @@ class LocalAdapter {
922
922
  this.collectionName = null;
923
923
  }
924
924
 
925
+ log(...args) {
926
+ if (this.debug) console.log('[LiekoDB]', ...args);
927
+ }
928
+
929
+ logRequest(operation, details, duration, responseSize) {
930
+ if (!this.debug) return;
931
+
932
+ const durationFormatted = Format.formatDuration(duration);
933
+
934
+ let sizePart = '';
935
+ if (typeof responseSize === 'number' && Number.isFinite(responseSize) && responseSize > 0) {
936
+ sizePart = ` | Response Size: ${Format.formatBytes(responseSize)}`;
937
+ }
938
+
939
+ this.log(
940
+ `${operation.toUpperCase()} | Collection: ${this.collectionName} | ` +
941
+ `Duration: ${durationFormatted}` +
942
+ sizePart +
943
+ (details ? ` | ${details}` : '')
944
+ );
945
+ }
946
+
947
+ logError(operation, err) {
948
+ console.error(
949
+ `[LiekoDB] ERROR - ${operation.toUpperCase()} | Collection: ${this.collectionName}` +
950
+ (err ? ` | ${err}` : '')
951
+ );
952
+ console.error(err)
953
+ }
954
+
925
955
  listCollections() {
926
956
  const collections = [];
927
957
 
@@ -1024,14 +1054,14 @@ class LocalAdapter {
1024
1054
 
1025
1055
  const duration = Utils.endTimer(start);
1026
1056
  const details = `Filters: ${Format.formatFilters(filters)} | Count: ${count}`;
1027
- Utils.logRequest('count', details, duration, Utils.getDataSize(count));
1057
+ this.logRequest('count', details, duration, Utils.getDataSize(count));
1028
1058
 
1029
1059
  return {
1030
1060
  data: count
1031
1061
  };
1032
1062
 
1033
1063
  } catch (err) {
1034
- Utils.logError('count', err);
1064
+ this.logError('count', err);
1035
1065
  return {
1036
1066
  error: {
1037
1067
  message: err.message || 'Failed to count documents',
@@ -1143,7 +1173,7 @@ class LocalAdapter {
1143
1173
  `${Format.formatOptions(options)}` +
1144
1174
  `${pageInfo} | Found: ${totalFilteredDocuments} | Returned: ${returnedCount}`;
1145
1175
 
1146
- Utils.logRequest(
1176
+ this.logRequest(
1147
1177
  'find',
1148
1178
  details,
1149
1179
  duration,
@@ -1153,7 +1183,7 @@ class LocalAdapter {
1153
1183
  return response;
1154
1184
 
1155
1185
  } catch (err) {
1156
- Utils.logError('find', err);
1186
+ this.logError('find', err);
1157
1187
 
1158
1188
  return {
1159
1189
  error: {
@@ -1184,14 +1214,14 @@ class LocalAdapter {
1184
1214
  }
1185
1215
 
1186
1216
  const duration = Utils.endTimer(start);
1187
- Utils.logRequest('find_By_Id', details, duration, Utils.getDataSize(document));
1217
+ this.logRequest('find_By_Id', details, duration, Utils.getDataSize(document));
1188
1218
 
1189
1219
  return {
1190
1220
  data: document ?? null
1191
1221
  };
1192
1222
 
1193
1223
  } catch (err) {
1194
- Utils.logError('findById', err);
1224
+ this.logError('findById', err);
1195
1225
  return {
1196
1226
  error: {
1197
1227
  message: err.message || 'Internal error during findById',
@@ -1291,12 +1321,12 @@ class LocalAdapter {
1291
1321
  const details = updated.length > 0
1292
1322
  ? `Inserted: ${inserted.length}, Updated: ${updated.length}`
1293
1323
  : `Inserted: ${inserted.length}`;
1294
- Utils.logRequest('insert', details, duration, Utils.getDataSize(responseData));
1324
+ this.logRequest('insert', details, duration, Utils.getDataSize(responseData));
1295
1325
 
1296
1326
  return { data: responseData };
1297
1327
 
1298
1328
  } catch (err) {
1299
- Utils.logError('insert', err);
1329
+ this.logError('insert', err);
1300
1330
  return {
1301
1331
  error: {
1302
1332
  message: err.message || 'Failed to insert documents',
@@ -1380,12 +1410,12 @@ class LocalAdapter {
1380
1410
 
1381
1411
  const duration = Utils.endTimer(start);
1382
1412
  const details = `Filters: ${Format.formatFilters(filters)} | Updated: ${updated} | ReturnType: ${returnType}`;
1383
- Utils.logRequest('update', details, duration, Utils.getDataSize(responseData));
1413
+ this.logRequest('update', details, duration, Utils.getDataSize(responseData));
1384
1414
 
1385
1415
  return { data: responseData };
1386
1416
 
1387
1417
  } catch (err) {
1388
- Utils.logError('update', err);
1418
+ this.logError('update', err);
1389
1419
  return {
1390
1420
  error: {
1391
1421
  message: err.message || 'Failed to update documents',
@@ -1429,12 +1459,12 @@ class LocalAdapter {
1429
1459
 
1430
1460
  const duration = Utils.endTimer(start);
1431
1461
  const details = `ID: ${id} | ReturnType: ${returnType} | Updated: 1`;
1432
- Utils.logRequest('update_By_Id', details, duration, Utils.getDataSize(responseData));
1462
+ this.logRequest('update_By_Id', details, duration, Utils.getDataSize(responseData));
1433
1463
 
1434
1464
  return { data: responseData };
1435
1465
 
1436
1466
  } catch (err) {
1437
- Utils.logError('update_By_Id', err);
1467
+ this.logError('update_By_Id', err);
1438
1468
  return {
1439
1469
  error: {
1440
1470
  message: err.message || 'Failed to update document by ID',
@@ -1483,7 +1513,7 @@ class LocalAdapter {
1483
1513
  ? `Filters: ${Format.formatFilters(filters)} | No documents matched`
1484
1514
  : `Filters: ${Format.formatFilters(filters)} | Deleted: ${deletedCount}`;
1485
1515
 
1486
- Utils.logRequest('delete', details, duration, Utils.getDataSize({ deletedCount }));
1516
+ this.logRequest('delete', details, duration, Utils.getDataSize({ deletedCount }));
1487
1517
 
1488
1518
  return {
1489
1519
  data: {
@@ -1494,7 +1524,7 @@ class LocalAdapter {
1494
1524
  };
1495
1525
 
1496
1526
  } catch (err) {
1497
- Utils.logError('delete', err);
1527
+ this.logError('delete', err);
1498
1528
  return {
1499
1529
  error: {
1500
1530
  message: err.message || 'Failed to delete documents',
@@ -1512,7 +1542,7 @@ class LocalAdapter {
1512
1542
  const duration = Utils.endTimer(start);
1513
1543
 
1514
1544
  if (!deleted) {
1515
- Utils.logRequest('delete_By_Id', `ID: ${id} | Not found`, duration);
1545
+ this.logRequest('delete_By_Id', `ID: ${id} | Not found`, duration);
1516
1546
  return {
1517
1547
  data: {
1518
1548
  deletedCount: 0,
@@ -1521,7 +1551,7 @@ class LocalAdapter {
1521
1551
  };
1522
1552
  }
1523
1553
 
1524
- Utils.logRequest('delete_By_Id', `ID: ${id} | Deleted`, duration);
1554
+ this.logRequest('delete_By_Id', `ID: ${id} | Deleted`, duration);
1525
1555
 
1526
1556
  return {
1527
1557
  data: {
@@ -1531,7 +1561,7 @@ class LocalAdapter {
1531
1561
  };
1532
1562
 
1533
1563
  } catch (err) {
1534
- Utils.logError('delete_By_Id', err);
1564
+ this.logError('delete_By_Id', err);
1535
1565
  return {
1536
1566
  error: {
1537
1567
  message: err.message || 'Failed to delete document by ID',
@@ -1566,7 +1596,7 @@ class LocalAdapter {
1566
1596
  }
1567
1597
 
1568
1598
  const duration = Utils.endTimer(start);
1569
- Utils.logRequest('dropCollection', 'Success', duration);
1599
+ this.logRequest('dropCollection', 'Success', duration);
1570
1600
 
1571
1601
  return {
1572
1602
  data: {
@@ -1576,7 +1606,7 @@ class LocalAdapter {
1576
1606
  };
1577
1607
 
1578
1608
  } catch (err) {
1579
- Utils.logError('dropCollection', err);
1609
+ this.logError('dropCollection', err);
1580
1610
  return {
1581
1611
  error: {
1582
1612
  message: err.message || 'Unexpected error during dropCollection',
@@ -1968,36 +1998,6 @@ class Utils {
1968
1998
  return require('crypto').randomBytes(8).toString('hex');
1969
1999
  }
1970
2000
 
1971
- static log(...args) {
1972
- if (this.debug) console.log('[LiekoDB]', ...args);
1973
- }
1974
-
1975
- static logRequest(operation, details, duration, responseSize) {
1976
- if (!this.debug) return;
1977
-
1978
- const durationFormatted = Format.formatDuration(duration);
1979
-
1980
- let sizePart = '';
1981
- if (typeof responseSize === 'number' && Number.isFinite(responseSize) && responseSize > 0) {
1982
- sizePart = ` | Response Size: ${Format.formatBytes(responseSize)}`;
1983
- }
1984
-
1985
- this.log(
1986
- `${operation.toUpperCase()} | Collection: ${this.collectionName} | ` +
1987
- `Duration: ${durationFormatted}` +
1988
- sizePart +
1989
- (details ? ` | ${details}` : '')
1990
- );
1991
- }
1992
-
1993
- static logError(operation, err) {
1994
- console.error(
1995
- `[LiekoDB] ERROR - ${operation.toUpperCase()} | Collection: ${this.collectionName}` +
1996
- (err ? ` | ${err}` : '')
1997
- );
1998
- console.error(err)
1999
- }
2000
-
2001
2001
  static getDataSize(data) {
2002
2002
  try {
2003
2003
  return Buffer.byteLength(JSON.stringify(data), 'utf8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liekodb",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Lightweight, MongoDB-like JSON database for Node.js",
5
5
  "main": "liekodb.js",
6
6
  "scripts": {