datastore-api 6.2.0 → 6.2.2

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.
@@ -3,7 +3,7 @@ import { setImmediate } from 'timers/promises';
3
3
  import { Datastore, PropertyFilter } from '@google-cloud/datastore';
4
4
  export { Datastore, Key, Query, Transaction } from '@google-cloud/datastore';
5
5
  import { entity } from '@google-cloud/datastore/build/src/entity';
6
- import { assertIsObject, assertIsDefined, assertIsString, assertIsArray, assertIsNumber, assert, getType } from 'assertate-debug';
6
+ import { assert, getType, assertIsObject, assertIsDefined, assertIsString, assertIsArray, assertIsNumber } from 'assertate-debug';
7
7
  import Debug from 'debug';
8
8
  import promClient from 'prom-client';
9
9
 
@@ -546,6 +546,35 @@ function _wrapNativeSuper(t) {
546
546
  }, _wrapNativeSuper(t);
547
547
  }
548
548
 
549
+ /*
550
+ * assert.ts
551
+ *
552
+ * Created by Dr. Maximillian Dornseif 2025-04-11 in datastore-api 6.0.1
553
+ */
554
+ /**
555
+ * Generates an type assertion message for the given `value`
556
+ *
557
+ * @param value value being type-checked
558
+ * @param type the expected value as a string; eg 'string', 'boolean', 'number'
559
+ * @param variableName the name of the variable being type-checked
560
+ * @param additionalMessage further information on failure
561
+ */
562
+ var AssertionMessage = function AssertionMessage(value, type, variableName, additionalMessage) {
563
+ var message = variableName ? variableName + " must be of type '" + type + "', '" + getType(value) + "' provided" : "expected value of type '" + type + "', '" + getType(value) + "' provided";
564
+ return additionalMessage ? message + ": " + additionalMessage : message;
565
+ };
566
+ /**
567
+ * Type-checks the provided `value` to be a symbol, throws an Error if it is not
568
+ *
569
+ * @param value the value to type-check as a symbol
570
+ * @param variableName the name of the variable to be type-checked
571
+ * @param additionalMessage further information on failure
572
+ * @throws {Error}
573
+ */
574
+ function assertIsKey(value, variableName, additionalMessage) {
575
+ assert(Datastore.isKey(value), AssertionMessage(value, "Key", variableName, additionalMessage));
576
+ }
577
+
549
578
  /** @ignore */
550
579
  var debug = /*#__PURE__*/Debug('ds:api');
551
580
  /** @ignore */
@@ -688,6 +717,31 @@ var Dstore = /*#__PURE__*/function () {
688
717
  });
689
718
  return entities;
690
719
  }
720
+ /** this is for save, insert, update and upsert and ensures _kkeyStr() handling.
721
+ *
722
+ */;
723
+ _proto.prepareEntitiesForDatastore = function prepareEntitiesForDatastore(entities) {
724
+ for (var _iterator2 = _createForOfIteratorHelperLoose(entities), _step2; !(_step2 = _iterator2()).done;) {
725
+ var e = _step2.value;
726
+ assertIsObject(e.key);
727
+ assertIsObject(e.data);
728
+ this.fixKeys([e.data]);
729
+ e.excludeLargeProperties = e.excludeLargeProperties === undefined ? true : e.excludeLargeProperties;
730
+ e.data = _extends({}, e.data, {
731
+ _keyStr: undefined
732
+ });
733
+ }
734
+ }
735
+ /** this is for save, insert, update and upsert and ensures _kkeyStr() handling.
736
+ *
737
+ */;
738
+ _proto.prepareEntitiesFromDatastore = function prepareEntitiesFromDatastore(entities) {
739
+ for (var _iterator3 = _createForOfIteratorHelperLoose(entities), _step3; !(_step3 = _iterator3()).done;) {
740
+ var e = _step3.value;
741
+ e.data[Datastore.KEY] = e.key;
742
+ this.fixKeys([e.data]);
743
+ }
744
+ }
691
745
  /** `get()` reads a [[IDstoreEntry]] from the Datastore.
692
746
  *
693
747
  * It returns [[IDstoreEntry]] or `null` if not found.
@@ -913,25 +967,16 @@ var Dstore = /*#__PURE__*/function () {
913
967
  /*#__PURE__*/
914
968
  function () {
915
969
  var _save = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(entities) {
916
- var ret, metricEnd, _iterator2, _step2, e, _iterator3, _step3, _e;
970
+ var ret, metricEnd;
917
971
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
918
972
  while (1) switch (_context4.prev = _context4.next) {
919
973
  case 0:
920
974
  assertIsArray(entities);
921
975
  metricEnd = metricHistogram.startTimer();
922
976
  _context4.prev = 2;
977
+ this.prepareEntitiesForDatastore(entities);
923
978
  // Within Transaction we don't get any answer here!
924
979
  // [ { mutationResults: [ [Object], [Object] ], indexUpdates: 51 } ]
925
- for (_iterator2 = _createForOfIteratorHelperLoose(entities); !(_step2 = _iterator2()).done;) {
926
- e = _step2.value;
927
- assertIsObject(e.key);
928
- assertIsObject(e.data);
929
- this.fixKeys([e.data]);
930
- e.excludeLargeProperties = e.excludeLargeProperties === undefined ? true : e.excludeLargeProperties;
931
- e.data = _extends({}, e.data, {
932
- _keyStr: undefined
933
- });
934
- }
935
980
  _context4.next = 6;
936
981
  return this.getDoT().save(entities);
937
982
  case 6:
@@ -943,11 +988,7 @@ var Dstore = /*#__PURE__*/function () {
943
988
  _context4.t0 = undefined;
944
989
  case 9:
945
990
  ret = _context4.t0;
946
- for (_iterator3 = _createForOfIteratorHelperLoose(entities); !(_step3 = _iterator3()).done;) {
947
- _e = _step3.value;
948
- _e.data[Datastore.KEY] = _e.key;
949
- this.fixKeys([_e.data]);
950
- }
991
+ this.prepareEntitiesFromDatastore(entities);
951
992
  _context4.next = 19;
952
993
  break;
953
994
  case 13:
@@ -1009,43 +1050,45 @@ var Dstore = /*#__PURE__*/function () {
1009
1050
  assertIsArray(entities);
1010
1051
  metricEnd = metricHistogram.startTimer();
1011
1052
  _context5.prev = 2;
1012
- _context5.next = 5;
1053
+ this.prepareEntitiesForDatastore(entities);
1054
+ _context5.next = 6;
1013
1055
  return this.getDoT().insert(entities);
1014
- case 5:
1056
+ case 6:
1015
1057
  _context5.t0 = _context5.sent;
1016
1058
  if (_context5.t0) {
1017
- _context5.next = 8;
1059
+ _context5.next = 9;
1018
1060
  break;
1019
1061
  }
1020
1062
  _context5.t0 = undefined;
1021
- case 8:
1063
+ case 9:
1022
1064
  ret = _context5.t0;
1023
- _context5.next = 17;
1065
+ this.prepareEntitiesFromDatastore(entities);
1066
+ _context5.next = 19;
1024
1067
  break;
1025
- case 11:
1026
- _context5.prev = 11;
1068
+ case 13:
1069
+ _context5.prev = 13;
1027
1070
  _context5.t1 = _context5["catch"](2);
1028
1071
  // console.error(error)
1029
1072
  metricFailureCounter.inc({
1030
1073
  operation: 'insert'
1031
1074
  });
1032
- _context5.next = 16;
1075
+ _context5.next = 18;
1033
1076
  return setImmediate();
1034
- case 16:
1077
+ case 18:
1035
1078
  throw new DstoreError('datastore.insert error', _context5.t1);
1036
- case 17:
1037
- _context5.prev = 17;
1079
+ case 19:
1080
+ _context5.prev = 19;
1038
1081
  metricEnd({
1039
1082
  operation: 'insert'
1040
1083
  });
1041
- return _context5.finish(17);
1042
- case 20:
1084
+ return _context5.finish(19);
1085
+ case 22:
1043
1086
  return _context5.abrupt("return", ret);
1044
- case 21:
1087
+ case 23:
1045
1088
  case "end":
1046
1089
  return _context5.stop();
1047
1090
  }
1048
- }, _callee5, this, [[2, 11, 17, 20]]);
1091
+ }, _callee5, this, [[2, 13, 19, 22]]);
1049
1092
  }));
1050
1093
  function insert(_x6) {
1051
1094
  return _insert.apply(this, arguments);
@@ -1087,43 +1130,45 @@ var Dstore = /*#__PURE__*/function () {
1087
1130
  });
1088
1131
  metricEnd = metricHistogram.startTimer();
1089
1132
  _context6.prev = 4;
1090
- _context6.next = 7;
1133
+ this.prepareEntitiesForDatastore(entities);
1134
+ _context6.next = 8;
1091
1135
  return this.getDoT().update(entities);
1092
- case 7:
1136
+ case 8:
1093
1137
  _context6.t0 = _context6.sent;
1094
1138
  if (_context6.t0) {
1095
- _context6.next = 10;
1139
+ _context6.next = 11;
1096
1140
  break;
1097
1141
  }
1098
1142
  _context6.t0 = undefined;
1099
- case 10:
1143
+ case 11:
1100
1144
  ret = _context6.t0;
1101
- _context6.next = 19;
1145
+ this.prepareEntitiesFromDatastore(entities);
1146
+ _context6.next = 21;
1102
1147
  break;
1103
- case 13:
1104
- _context6.prev = 13;
1148
+ case 15:
1149
+ _context6.prev = 15;
1105
1150
  _context6.t1 = _context6["catch"](4);
1106
1151
  // console.error(error)
1107
1152
  metricFailureCounter.inc({
1108
1153
  operation: 'update'
1109
1154
  });
1110
- _context6.next = 18;
1155
+ _context6.next = 20;
1111
1156
  return setImmediate();
1112
- case 18:
1157
+ case 20:
1113
1158
  throw new DstoreError('datastore.update error', _context6.t1);
1114
- case 19:
1115
- _context6.prev = 19;
1159
+ case 21:
1160
+ _context6.prev = 21;
1116
1161
  metricEnd({
1117
1162
  operation: 'update'
1118
1163
  });
1119
- return _context6.finish(19);
1120
- case 22:
1164
+ return _context6.finish(21);
1165
+ case 24:
1121
1166
  return _context6.abrupt("return", ret);
1122
- case 23:
1167
+ case 25:
1123
1168
  case "end":
1124
1169
  return _context6.stop();
1125
1170
  }
1126
- }, _callee6, this, [[4, 13, 19, 22]]);
1171
+ }, _callee6, this, [[4, 15, 21, 24]]);
1127
1172
  }));
1128
1173
  function update(_x7) {
1129
1174
  return _update.apply(this, arguments);
@@ -1280,7 +1325,7 @@ var Dstore = /*#__PURE__*/function () {
1280
1325
  /*#__PURE__*/
1281
1326
  function () {
1282
1327
  var _query = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(kindName, filters, limit, ordering, selection, cursor) {
1283
- var q, _iterator4, _step4, filterSpec, _iterator5, _step5, orderField;
1328
+ var q, _iterator4, _step4, filterSpec, _iterator5, _step5, orderField, ret;
1284
1329
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1285
1330
  while (1) switch (_context9.prev = _context9.next) {
1286
1331
  case 0:
@@ -1318,26 +1363,27 @@ var Dstore = /*#__PURE__*/function () {
1318
1363
  q.select(selection);
1319
1364
  }
1320
1365
  _context9.next = 15;
1321
- return this.runQuery(q);
1366
+ return this.getDoT().runQuery(q);
1322
1367
  case 15:
1323
- return _context9.abrupt("return", _context9.sent);
1324
- case 18:
1325
- _context9.prev = 18;
1368
+ ret = _context9.sent;
1369
+ return _context9.abrupt("return", [this.fixKeys(ret[0]), ret[1]]);
1370
+ case 19:
1371
+ _context9.prev = 19;
1326
1372
  _context9.t0 = _context9["catch"](7);
1327
- _context9.next = 22;
1373
+ _context9.next = 23;
1328
1374
  return setImmediate();
1329
- case 22:
1375
+ case 23:
1330
1376
  throw new DstoreError('datastore.query error', _context9.t0, {
1331
1377
  kindName: kindName,
1332
1378
  filters: filters,
1333
1379
  limit: limit,
1334
1380
  ordering: ordering
1335
1381
  });
1336
- case 23:
1382
+ case 24:
1337
1383
  case "end":
1338
1384
  return _context9.stop();
1339
1385
  }
1340
- }, _callee9, this, [[7, 18]]);
1386
+ }, _callee9, this, [[7, 19]]);
1341
1387
  }));
1342
1388
  function query(_x10, _x11, _x12, _x13, _x14, _x15) {
1343
1389
  return _query.apply(this, arguments);
@@ -1349,12 +1395,21 @@ var Dstore = /*#__PURE__*/function () {
1349
1395
  * It takes a Parameter object and returns an AsyncIterable.
1350
1396
  * Entities returned have been processed by `fixKeys()`.
1351
1397
  *
1398
+ * Can be used with `for await` loops like this:
1399
+ *
1400
+ * ```typescript
1401
+ * for await (const entity of dstore.iterate({ kindName: 'p_ReservierungsAbruf', filters: [['verbucht', '=', true]]})) {
1402
+ * console.log(entity)
1403
+ * }
1404
+ * ```
1405
+ *
1352
1406
  * @param kindName Name of the [[Datastore]][Kind](https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers) ("Table") which should be searched.
1353
1407
  * @param filters List of [[Query]] filter() calls.
1354
1408
  * @param limit Maximum Number of Results to return.
1355
1409
  * @param ordering List of [[Query]] order() calls.
1356
1410
  * @param selection selectionList of [[Query]] select() calls.
1357
1411
  *
1412
+ * @throws [[DstoreError]]
1358
1413
  * @category Additional
1359
1414
  */
1360
1415
  ;
@@ -1398,72 +1453,73 @@ var Dstore = /*#__PURE__*/function () {
1398
1453
  _iteratorAbruptCompletion = false;
1399
1454
  _didIteratorError = false;
1400
1455
  _context10.prev = 11;
1401
- _iterator = _asyncIterator(_this.getDoT().runStream(q));
1456
+ _iterator = _asyncIterator(q.runStream());
1402
1457
  case 13:
1403
1458
  _context10.next = 15;
1404
1459
  return _awaitAsyncGenerator(_iterator.next());
1405
1460
  case 15:
1406
1461
  if (!(_iteratorAbruptCompletion = !(_step = _context10.sent).done)) {
1407
- _context10.next = 24;
1462
+ _context10.next = 25;
1408
1463
  break;
1409
1464
  }
1410
1465
  _entity = _step.value;
1411
1466
  ret = _this.fixKeys([_entity])[0];
1412
1467
  assertIsDefined(ret, 'datastore.iterate: entity is undefined');
1413
- _context10.next = 21;
1468
+ assertIsKey(ret[Datastore.KEY]);
1469
+ _context10.next = 22;
1414
1470
  return ret;
1415
- case 21:
1471
+ case 22:
1416
1472
  _iteratorAbruptCompletion = false;
1417
1473
  _context10.next = 13;
1418
1474
  break;
1419
- case 24:
1420
- _context10.next = 30;
1475
+ case 25:
1476
+ _context10.next = 31;
1421
1477
  break;
1422
- case 26:
1423
- _context10.prev = 26;
1478
+ case 27:
1479
+ _context10.prev = 27;
1424
1480
  _context10.t0 = _context10["catch"](11);
1425
1481
  _didIteratorError = true;
1426
1482
  _iteratorError = _context10.t0;
1427
- case 30:
1428
- _context10.prev = 30;
1483
+ case 31:
1429
1484
  _context10.prev = 31;
1485
+ _context10.prev = 32;
1430
1486
  if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
1431
- _context10.next = 35;
1487
+ _context10.next = 36;
1432
1488
  break;
1433
1489
  }
1434
- _context10.next = 35;
1490
+ _context10.next = 36;
1435
1491
  return _awaitAsyncGenerator(_iterator["return"]());
1436
- case 35:
1437
- _context10.prev = 35;
1492
+ case 36:
1493
+ _context10.prev = 36;
1438
1494
  if (!_didIteratorError) {
1439
- _context10.next = 38;
1495
+ _context10.next = 39;
1440
1496
  break;
1441
1497
  }
1442
1498
  throw _iteratorError;
1443
- case 38:
1444
- return _context10.finish(35);
1445
1499
  case 39:
1446
- return _context10.finish(30);
1500
+ return _context10.finish(36);
1447
1501
  case 40:
1448
- _context10.next = 47;
1502
+ return _context10.finish(31);
1503
+ case 41:
1504
+ _context10.next = 48;
1449
1505
  break;
1450
- case 42:
1451
- _context10.prev = 42;
1506
+ case 43:
1507
+ _context10.prev = 43;
1452
1508
  _context10.t1 = _context10["catch"](3);
1453
- _context10.next = 46;
1509
+ _context10.next = 47;
1454
1510
  return _awaitAsyncGenerator(setImmediate());
1455
- case 46:
1511
+ case 47:
1456
1512
  throw new DstoreError('datastore.query error', _context10.t1, {
1457
1513
  kindName: kindName,
1458
1514
  filters: filters,
1459
1515
  limit: limit,
1460
1516
  ordering: ordering
1461
1517
  });
1462
- case 47:
1518
+ case 48:
1463
1519
  case "end":
1464
1520
  return _context10.stop();
1465
1521
  }
1466
- }, _callee10, null, [[3, 42], [11, 26, 30, 40], [31,, 35, 39]]);
1522
+ }, _callee10, null, [[3, 43], [11, 27, 31, 41], [32,, 36, 40]]);
1467
1523
  }))();
1468
1524
  }
1469
1525
  /** Allocate one ID in the Datastore.
@@ -1617,34 +1673,5 @@ var DstoreError = /*#__PURE__*/function (_Error) {
1617
1673
  return DstoreError;
1618
1674
  }(/*#__PURE__*/_wrapNativeSuper(Error));
1619
1675
 
1620
- /*
1621
- * assert.ts
1622
- *
1623
- * Created by Dr. Maximillian Dornseif 2025-04-11 in datastore-api 6.0.1
1624
- */
1625
- /**
1626
- * Generates an type assertion message for the given `value`
1627
- *
1628
- * @param value value being type-checked
1629
- * @param type the expected value as a string; eg 'string', 'boolean', 'number'
1630
- * @param variableName the name of the variable being type-checked
1631
- * @param additionalMessage further information on failure
1632
- */
1633
- var AssertionMessage = function AssertionMessage(value, type, variableName, additionalMessage) {
1634
- var message = variableName ? variableName + " must be of type '" + type + "', '" + getType(value) + "' provided" : "expected value of type '" + type + "', '" + getType(value) + "' provided";
1635
- return additionalMessage ? message + ": " + additionalMessage : message;
1636
- };
1637
- /**
1638
- * Type-checks the provided `value` to be a symbol, throws an Error if it is not
1639
- *
1640
- * @param value the value to type-check as a symbol
1641
- * @param variableName the name of the variable to be type-checked
1642
- * @param additionalMessage further information on failure
1643
- * @throws {Error}
1644
- */
1645
- function assertIsKey(value, variableName, additionalMessage) {
1646
- assert(Datastore.isKey(value), AssertionMessage(value, "Key", variableName, additionalMessage));
1647
- }
1648
-
1649
1676
  export { Dstore, DstoreError, KEYSYM, assertIsKey };
1650
1677
  //# sourceMappingURL=datastore-api.esm.js.map