@exabugs/dynamodb-client 1.3.42 → 1.3.44

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 (58) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +153 -6
  3. package/dist/client/Collection.d.ts.map +1 -1
  4. package/dist/client/Collection.js +9 -3
  5. package/dist/client/Collection.js.map +1 -1
  6. package/dist/client/FindCursor.d.ts +28 -1
  7. package/dist/client/FindCursor.d.ts.map +1 -1
  8. package/dist/client/FindCursor.js +34 -1
  9. package/dist/client/FindCursor.js.map +1 -1
  10. package/dist/server/handler.cjs +274 -39
  11. package/dist/server/handler.cjs.map +3 -3
  12. package/dist/server/operations/deleteMany.d.ts.map +1 -1
  13. package/dist/server/operations/deleteMany.js +26 -1
  14. package/dist/server/operations/deleteMany.js.map +1 -1
  15. package/dist/server/operations/deleteOne.d.ts.map +1 -1
  16. package/dist/server/operations/deleteOne.js +8 -2
  17. package/dist/server/operations/deleteOne.js.map +1 -1
  18. package/dist/server/operations/find/idQuery.d.ts.map +1 -1
  19. package/dist/server/operations/find/idQuery.js +12 -0
  20. package/dist/server/operations/find/idQuery.js.map +1 -1
  21. package/dist/server/operations/find/nearQuery.d.ts.map +1 -1
  22. package/dist/server/operations/find/nearQuery.js +9 -0
  23. package/dist/server/operations/find/nearQuery.js.map +1 -1
  24. package/dist/server/operations/find/shadowQuery.d.ts.map +1 -1
  25. package/dist/server/operations/find/shadowQuery.js +23 -5
  26. package/dist/server/operations/find/shadowQuery.js.map +1 -1
  27. package/dist/server/operations/insertMany.d.ts.map +1 -1
  28. package/dist/server/operations/insertMany.js +16 -2
  29. package/dist/server/operations/insertMany.js.map +1 -1
  30. package/dist/server/operations/insertOne.d.ts.map +1 -1
  31. package/dist/server/operations/insertOne.js +5 -1
  32. package/dist/server/operations/insertOne.js.map +1 -1
  33. package/dist/server/operations/updateMany.d.ts.map +1 -1
  34. package/dist/server/operations/updateMany.js +25 -1
  35. package/dist/server/operations/updateMany.js.map +1 -1
  36. package/dist/server/operations/updateOne.d.ts.map +1 -1
  37. package/dist/server/operations/updateOne.js +10 -2
  38. package/dist/server/operations/updateOne.js.map +1 -1
  39. package/dist/server/query/nearSearch.d.ts.map +1 -1
  40. package/dist/server/query/nearSearch.js +62 -0
  41. package/dist/server/query/nearSearch.js.map +1 -1
  42. package/dist/server/types.d.ts +6 -5
  43. package/dist/server/types.d.ts.map +1 -1
  44. package/dist/server/types.js +0 -5
  45. package/dist/server/types.js.map +1 -1
  46. package/dist/server/utils/cost-tracker.d.ts +62 -0
  47. package/dist/server/utils/cost-tracker.d.ts.map +1 -0
  48. package/dist/server/utils/cost-tracker.js +76 -0
  49. package/dist/server/utils/cost-tracker.js.map +1 -0
  50. package/dist/shared/types/consumed-capacity.d.ts +36 -0
  51. package/dist/shared/types/consumed-capacity.d.ts.map +1 -0
  52. package/dist/shared/types/consumed-capacity.js +2 -0
  53. package/dist/shared/types/consumed-capacity.js.map +1 -0
  54. package/dist/shared/types/index.d.ts +6 -4
  55. package/dist/shared/types/index.d.ts.map +1 -1
  56. package/dist/shared/types/index.js +2 -7
  57. package/dist/shared/types/index.js.map +1 -1
  58. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- // @exabugs/dynamodb-client v1.3.42
2
- // Built: 2026-01-15T00:42:00.085Z
1
+ // @exabugs/dynamodb-client v1.3.44
2
+ // Built: 2026-01-17T08:17:02.209Z
3
3
  "use strict";
4
4
  var __create = Object.create;
5
5
  var __defProp = Object.defineProperty;
@@ -54,10 +54,18 @@ var init_http = __esm({
54
54
  }
55
55
  });
56
56
 
57
+ // src/shared/types/consumed-capacity.ts
58
+ var init_consumed_capacity = __esm({
59
+ "src/shared/types/consumed-capacity.ts"() {
60
+ "use strict";
61
+ }
62
+ });
63
+
57
64
  // src/shared/types/index.ts
58
65
  var init_types = __esm({
59
66
  "src/shared/types/index.ts"() {
60
67
  "use strict";
68
+ init_consumed_capacity();
61
69
  }
62
70
  });
63
71
 
@@ -29927,6 +29935,72 @@ var init_chunking = __esm({
29927
29935
  }
29928
29936
  });
29929
29937
 
29938
+ // src/server/utils/cost-tracker.ts
29939
+ var CostTracker;
29940
+ var init_cost_tracker = __esm({
29941
+ "src/server/utils/cost-tracker.ts"() {
29942
+ "use strict";
29943
+ CostTracker = class {
29944
+ static {
29945
+ __name(this, "CostTracker");
29946
+ }
29947
+ totalRCU = 0;
29948
+ totalWCU = 0;
29949
+ operationCount = 0;
29950
+ /**
29951
+ * ConsumedCapacityを追加
29952
+ *
29953
+ * DynamoDB操作のConsumedCapacityを累積します。
29954
+ * undefinedが渡された場合は何もしません(エラーにしない)。
29955
+ *
29956
+ * AWS SDKのConsumedCapacityは以下のフィールドを持ちます:
29957
+ * - CapacityUnits: 総キャパシティユニット(RCU + WCU)
29958
+ * - ReadCapacityUnits: 読み取りキャパシティユニット
29959
+ * - WriteCapacityUnits: 書き込みキャパシティユニット
29960
+ *
29961
+ * このメソッドはReadCapacityUnitsとWriteCapacityUnitsを優先的に使用し、
29962
+ * 存在しない場合はCapacityUnitsを読み取りとして扱います。
29963
+ *
29964
+ * @param consumedCapacity - DynamoDB操作のConsumedCapacity
29965
+ */
29966
+ add(consumedCapacity) {
29967
+ if (!consumedCapacity) {
29968
+ return;
29969
+ }
29970
+ const rcu = consumedCapacity.ReadCapacityUnits ?? 0;
29971
+ const wcu = consumedCapacity.WriteCapacityUnits ?? 0;
29972
+ this.totalRCU += rcu;
29973
+ this.totalWCU += wcu;
29974
+ this.operationCount += 1;
29975
+ }
29976
+ /**
29977
+ * 集計結果を取得
29978
+ *
29979
+ * これまでに追加されたConsumedCapacityの集計結果を返します。
29980
+ *
29981
+ * @returns 集計されたコスト情報
29982
+ */
29983
+ getAggregated() {
29984
+ return {
29985
+ totalRCU: this.totalRCU,
29986
+ totalWCU: this.totalWCU,
29987
+ operationCount: this.operationCount
29988
+ };
29989
+ }
29990
+ /**
29991
+ * リセット
29992
+ *
29993
+ * 累積されたコスト情報をクリアします。
29994
+ */
29995
+ reset() {
29996
+ this.totalRCU = 0;
29997
+ this.totalWCU = 0;
29998
+ this.operationCount = 0;
29999
+ }
30000
+ };
30001
+ }
30002
+ });
30003
+
29930
30004
  // src/server/utils/dynamodb.ts
29931
30005
  function getDBClient() {
29932
30006
  if (!dbClient) {
@@ -30053,6 +30127,13 @@ var init_converter = __esm({
30053
30127
  });
30054
30128
 
30055
30129
  // src/server/query/nearSearch.ts
30130
+ function coversMaxDistance(precision, maxDistance) {
30131
+ const coverage = GEOHASH_COVERAGE[precision];
30132
+ if (!coverage) {
30133
+ return false;
30134
+ }
30135
+ return coverage >= maxDistance;
30136
+ }
30056
30137
  async function executeNearSearch(nearQuery, fieldName, limit, searchFunction, config = DEFAULT_GEOHASH_CONFIG) {
30057
30138
  const { latitude, longitude } = extractCoordinatesFromNearQuery(nearQuery);
30058
30139
  const maxDistance = extractMaxDistanceFromNearQuery(nearQuery);
@@ -30072,6 +30153,43 @@ async function executeNearSearch(nearQuery, fieldName, limit, searchFunction, co
30072
30153
  allCandidates.push(candidate);
30073
30154
  }
30074
30155
  }
30156
+ if (maxDistance !== void 0) {
30157
+ let candidatesWithinDistance = 0;
30158
+ for (const candidate of allCandidates) {
30159
+ const location = candidate[fieldName];
30160
+ if (location && typeof location.latitude === "number" && typeof location.longitude === "number") {
30161
+ const distance = calculateDistance(
30162
+ latitude,
30163
+ longitude,
30164
+ location.latitude,
30165
+ location.longitude
30166
+ );
30167
+ if (distance <= maxDistance) {
30168
+ candidatesWithinDistance++;
30169
+ }
30170
+ }
30171
+ }
30172
+ if (candidatesWithinDistance >= limit) {
30173
+ console.log("[nearSearch] Early termination: found enough candidates within maxDistance", {
30174
+ candidatesWithinDistance,
30175
+ limit,
30176
+ maxDistance,
30177
+ precision,
30178
+ iterations
30179
+ });
30180
+ break;
30181
+ }
30182
+ if (coversMaxDistance(precision, maxDistance)) {
30183
+ console.log("[nearSearch] Early termination: current precision covers maxDistance", {
30184
+ precision,
30185
+ maxDistance,
30186
+ coverage: GEOHASH_COVERAGE[precision],
30187
+ candidatesWithinDistance,
30188
+ iterations
30189
+ });
30190
+ break;
30191
+ }
30192
+ }
30075
30193
  precision--;
30076
30194
  }
30077
30195
  const documentsWithDistance = allCandidates.map((doc) => {
@@ -30120,10 +30238,28 @@ async function executeNearSearch(nearQuery, fieldName, limit, searchFunction, co
30120
30238
  }
30121
30239
  };
30122
30240
  }
30241
+ var GEOHASH_COVERAGE;
30123
30242
  var init_nearSearch = __esm({
30124
30243
  "src/server/query/nearSearch.ts"() {
30125
30244
  "use strict";
30126
30245
  init_geohash();
30246
+ GEOHASH_COVERAGE = {
30247
+ 8: 19 * 3,
30248
+ // ±19m × 3 = 約57m
30249
+ 7: 76 * 3,
30250
+ // ±76m × 3 = 約228m
30251
+ 6: 610 * 3,
30252
+ // ±610m × 3 = 約1,830m (1.8km)
30253
+ 5: 2400 * 3,
30254
+ // ±2.4km × 3 = 約7,200m (7.2km)
30255
+ 4: 2e4 * 3,
30256
+ // ±20km × 3 = 約60,000m (60km)
30257
+ 3: 78e3 * 3,
30258
+ // ±78km × 3 = 約234,000m (234km)
30259
+ 2: 63e4 * 3
30260
+ // ±630km × 3 = 約1,890,000m (1,890km)
30261
+ };
30262
+ __name(coversMaxDistance, "coversMaxDistance");
30127
30263
  __name(executeNearSearch, "executeNearSearch");
30128
30264
  }
30129
30265
  });
@@ -30414,6 +30550,7 @@ async function executeIdQuery(resource, normalizedParams, requestId) {
30414
30550
  async function executeSpecificIdQuery(resource, targetId, requestId) {
30415
30551
  const dbClient2 = getDBClient();
30416
30552
  const tableName = getTableName();
30553
+ const costTracker = new CostTracker();
30417
30554
  const queryResult = await executeDynamoDBOperation(
30418
30555
  () => dbClient2.send(
30419
30556
  new import_lib_dynamodb2.QueryCommand({
@@ -30423,11 +30560,13 @@ async function executeSpecificIdQuery(resource, targetId, requestId) {
30423
30560
  ":pk": resource,
30424
30561
  ":sk": `id#${targetId}`
30425
30562
  },
30426
- ConsistentRead: true
30563
+ ConsistentRead: true,
30564
+ ReturnConsumedCapacity: "TOTAL"
30427
30565
  })
30428
30566
  ),
30429
30567
  "Query"
30430
30568
  );
30569
+ costTracker.add(queryResult.ConsumedCapacity);
30431
30570
  const mainRecords = queryResult.Items || [];
30432
30571
  const items = mainRecords.map((item) => extractCleanRecord(item));
30433
30572
  logger6.info("ID specific query succeeded", {
@@ -30441,12 +30580,14 @@ async function executeSpecificIdQuery(resource, targetId, requestId) {
30441
30580
  pageInfo: {
30442
30581
  hasNextPage: false,
30443
30582
  hasPreviousPage: false
30444
- }
30583
+ },
30584
+ consumedCapacity: costTracker.getAggregated()
30445
30585
  };
30446
30586
  }
30447
30587
  async function executeAllRecordsQuery(resource, sort, perPage, nextToken, parsedFilters, requestId) {
30448
30588
  const dbClient2 = getDBClient();
30449
30589
  const tableName = getTableName();
30590
+ const costTracker = new CostTracker();
30450
30591
  let exclusiveStartKey;
30451
30592
  if (nextToken) {
30452
30593
  const decoded = decodeNextToken(nextToken);
@@ -30467,11 +30608,13 @@ async function executeAllRecordsQuery(resource, sort, perPage, nextToken, parsed
30467
30608
  ScanIndexForward: sort.order === "ASC",
30468
30609
  Limit: perPage,
30469
30610
  ExclusiveStartKey: exclusiveStartKey,
30470
- ConsistentRead: true
30611
+ ConsistentRead: true,
30612
+ ReturnConsumedCapacity: "TOTAL"
30471
30613
  })
30472
30614
  ),
30473
30615
  "Query"
30474
30616
  );
30617
+ costTracker.add(queryResult.ConsumedCapacity);
30475
30618
  const mainRecords = queryResult.Items || [];
30476
30619
  if (mainRecords.length === 0) {
30477
30620
  return {
@@ -30479,7 +30622,8 @@ async function executeAllRecordsQuery(resource, sort, perPage, nextToken, parsed
30479
30622
  pageInfo: {
30480
30623
  hasNextPage: false,
30481
30624
  hasPreviousPage: false
30482
- }
30625
+ },
30626
+ consumedCapacity: costTracker.getAggregated()
30483
30627
  };
30484
30628
  }
30485
30629
  let items = mainRecords.map((item) => extractCleanRecord(item));
@@ -30503,7 +30647,8 @@ async function executeAllRecordsQuery(resource, sort, perPage, nextToken, parsed
30503
30647
  hasNextPage,
30504
30648
  hasPreviousPage: !!nextToken
30505
30649
  },
30506
- ...nextTokenValue && { nextToken: nextTokenValue }
30650
+ ...nextTokenValue && { nextToken: nextTokenValue },
30651
+ consumedCapacity: costTracker.getAggregated()
30507
30652
  };
30508
30653
  }
30509
30654
  var import_lib_dynamodb2, logger6;
@@ -30512,6 +30657,7 @@ var init_idQuery = __esm({
30512
30657
  "use strict";
30513
30658
  import_lib_dynamodb2 = __toESM(require_dist_cjs66(), 1);
30514
30659
  init_shared();
30660
+ init_cost_tracker();
30515
30661
  init_dynamodb3();
30516
30662
  init_pagination();
30517
30663
  init_utils4();
@@ -30534,6 +30680,7 @@ async function executeNearQuery(resource, fieldName, nearQuery, limit, requestId
30534
30680
  nearQuery,
30535
30681
  limit
30536
30682
  });
30683
+ const costTracker = new CostTracker();
30537
30684
  const searchFunction = /* @__PURE__ */ __name(async (geohashPrefix) => {
30538
30685
  const dbClient2 = getDBClient();
30539
30686
  const tableName = getTableName();
@@ -30553,12 +30700,14 @@ async function executeNearQuery(resource, fieldName, nearQuery, limit, requestId
30553
30700
  ":pk": resource,
30554
30701
  ":skPrefix": `${fieldName}#${geohashPrefix}`
30555
30702
  },
30556
- ConsistentRead: false
30703
+ ConsistentRead: false,
30557
30704
  // シャドウレコードは結果整合性で十分
30705
+ ReturnConsumedCapacity: "TOTAL"
30558
30706
  })
30559
30707
  ),
30560
30708
  "Query"
30561
30709
  );
30710
+ costTracker.add(queryResult.ConsumedCapacity);
30562
30711
  const shadowRecords = queryResult.Items || [];
30563
30712
  logger7.debug("Shadow records found", {
30564
30713
  requestId,
@@ -30589,11 +30738,13 @@ async function executeNearQuery(resource, fieldName, nearQuery, limit, requestId
30589
30738
  // venues
30590
30739
  ":sk": `id#${id}`
30591
30740
  },
30592
- ConsistentRead: true
30741
+ ConsistentRead: true,
30742
+ ReturnConsumedCapacity: "TOTAL"
30593
30743
  })
30594
30744
  ),
30595
30745
  "Query"
30596
30746
  );
30747
+ costTracker.add(result2.ConsumedCapacity);
30597
30748
  return result2.Items?.[0];
30598
30749
  })
30599
30750
  );
@@ -30638,7 +30789,8 @@ async function executeNearQuery(resource, fieldName, nearQuery, limit, requestId
30638
30789
  hasNextPage: false,
30639
30790
  // $near検索はページネーション非対応
30640
30791
  hasPreviousPage: false
30641
- }
30792
+ },
30793
+ consumedCapacity: costTracker.getAggregated()
30642
30794
  };
30643
30795
  }
30644
30796
  var import_lib_dynamodb3, logger7;
@@ -30649,6 +30801,7 @@ var init_nearQuery = __esm({
30649
30801
  init_geohash();
30650
30802
  init_shared();
30651
30803
  init_nearSearch();
30804
+ init_cost_tracker();
30652
30805
  init_dynamodb3();
30653
30806
  logger7 = createLogger({
30654
30807
  service: "near-query",
@@ -30662,6 +30815,7 @@ var init_nearQuery = __esm({
30662
30815
  async function executeShadowQuery(resource, normalizedParams, requestId) {
30663
30816
  const { sort, pagination, parsedFilters } = normalizedParams;
30664
30817
  const { perPage, nextToken } = pagination;
30818
+ const costTracker = new CostTracker();
30665
30819
  logger8.debug("Executing shadow query", {
30666
30820
  requestId,
30667
30821
  resource,
@@ -30675,6 +30829,7 @@ async function executeShadowQuery(resource, normalizedParams, requestId) {
30675
30829
  perPage,
30676
30830
  nextToken,
30677
30831
  optimizableFilter,
30832
+ costTracker,
30678
30833
  requestId
30679
30834
  );
30680
30835
  const recordIds = extractRecordIds(shadowRecords.Items || []);
@@ -30684,10 +30839,11 @@ async function executeShadowQuery(resource, normalizedParams, requestId) {
30684
30839
  pageInfo: {
30685
30840
  hasNextPage: false,
30686
30841
  hasPreviousPage: false
30687
- }
30842
+ },
30843
+ consumedCapacity: costTracker.getAggregated()
30688
30844
  };
30689
30845
  }
30690
- const mainRecords = await fetchMainRecords(resource, recordIds, requestId);
30846
+ const mainRecords = await fetchMainRecords(resource, recordIds, costTracker, requestId);
30691
30847
  const recordMap = new Map(
30692
30848
  mainRecords.map((item) => {
30693
30849
  const data2 = item.data;
@@ -30724,10 +30880,11 @@ async function executeShadowQuery(resource, normalizedParams, requestId) {
30724
30880
  hasNextPage,
30725
30881
  hasPreviousPage: !!nextToken
30726
30882
  },
30727
- ...nextTokenValue && { nextToken: nextTokenValue }
30883
+ ...nextTokenValue && { nextToken: nextTokenValue },
30884
+ consumedCapacity: costTracker.getAggregated()
30728
30885
  };
30729
30886
  }
30730
- async function executeShadowRecordQuery(resource, sort, perPage, nextToken, optimizableFilter, _requestId) {
30887
+ async function executeShadowRecordQuery(resource, sort, perPage, nextToken, optimizableFilter, costTracker, _requestId) {
30731
30888
  const dbClient2 = getDBClient();
30732
30889
  const tableName = getTableName();
30733
30890
  let exclusiveStartKey;
@@ -30743,7 +30900,7 @@ async function executeShadowRecordQuery(resource, sort, perPage, nextToken, opti
30743
30900
  sort.field,
30744
30901
  optimizableFilter
30745
30902
  );
30746
- return await executeDynamoDBOperation(
30903
+ const result = await executeDynamoDBOperation(
30747
30904
  () => dbClient2.send(
30748
30905
  new import_lib_dynamodb4.QueryCommand({
30749
30906
  TableName: tableName,
@@ -30752,11 +30909,14 @@ async function executeShadowRecordQuery(resource, sort, perPage, nextToken, opti
30752
30909
  ScanIndexForward: sort.order === "ASC",
30753
30910
  Limit: perPage,
30754
30911
  ExclusiveStartKey: exclusiveStartKey,
30755
- ConsistentRead: true
30912
+ ConsistentRead: true,
30913
+ ReturnConsumedCapacity: "TOTAL"
30756
30914
  })
30757
30915
  ),
30758
30916
  "Query"
30759
30917
  );
30918
+ costTracker.add(result.ConsumedCapacity);
30919
+ return result;
30760
30920
  }
30761
30921
  function buildKeyCondition(resource, sortField, optimizableFilter) {
30762
30922
  const expressionAttributeValues = {
@@ -30846,7 +31006,7 @@ function extractRecordIds(shadowRecords) {
30846
31006
  return parts.length > 1 ? parts[1] : null;
30847
31007
  }).filter((id) => id !== null);
30848
31008
  }
30849
- async function fetchMainRecords(resource, recordIds, requestId) {
31009
+ async function fetchMainRecords(resource, recordIds, costTracker, requestId) {
30850
31010
  const dbClient2 = getDBClient();
30851
31011
  const tableName = getTableName();
30852
31012
  const uniqueRecordIds = Array.from(new Set(recordIds));
@@ -30861,11 +31021,17 @@ async function fetchMainRecords(resource, recordIds, requestId) {
30861
31021
  })),
30862
31022
  ConsistentRead: true
30863
31023
  }
30864
- }
31024
+ },
31025
+ ReturnConsumedCapacity: "TOTAL"
30865
31026
  })
30866
31027
  ),
30867
31028
  "BatchGetItem"
30868
31029
  );
31030
+ if (batchGetResult.ConsumedCapacity) {
31031
+ for (const capacity of batchGetResult.ConsumedCapacity) {
31032
+ costTracker.add(capacity);
31033
+ }
31034
+ }
30869
31035
  const mainRecords = batchGetResult.Responses?.[tableName] || [];
30870
31036
  logger8.debug("Main records fetched", {
30871
31037
  requestId,
@@ -30882,6 +31048,7 @@ var init_shadowQuery = __esm({
30882
31048
  import_lib_dynamodb4 = __toESM(require_dist_cjs66(), 1);
30883
31049
  init_formatting();
30884
31050
  init_shared();
31051
+ init_cost_tracker();
30885
31052
  init_dynamodb3();
30886
31053
  init_pagination();
30887
31054
  init_utils4();
@@ -30973,6 +31140,7 @@ __export(deleteMany_exports, {
30973
31140
  });
30974
31141
  async function handleDeleteMany(resource, params, requestId) {
30975
31142
  const startTime = Date.now();
31143
+ const costTracker = new CostTracker();
30976
31144
  let ids;
30977
31145
  if ("ids" in params) {
30978
31146
  ids = params.ids;
@@ -31001,7 +31169,8 @@ async function handleDeleteMany(resource, params, requestId) {
31001
31169
  count: 0,
31002
31170
  successIds: {},
31003
31171
  failedIds: {},
31004
- errors: {}
31172
+ errors: {},
31173
+ consumedCapacity: costTracker.getAggregated()
31005
31174
  };
31006
31175
  }
31007
31176
  logLargeBatchWarning("deleteMany", ids.length, requestId, resource);
@@ -31019,11 +31188,19 @@ async function handleDeleteMany(resource, params, requestId) {
31019
31188
  Keys: keys,
31020
31189
  ConsistentRead: true
31021
31190
  }
31022
- }
31191
+ },
31192
+ ReturnConsumedCapacity: "TOTAL"
31023
31193
  })
31024
31194
  ),
31025
31195
  "BatchGetItem"
31026
31196
  );
31197
+ if (Array.isArray(batchGetResult.ConsumedCapacity)) {
31198
+ for (const capacity of batchGetResult.ConsumedCapacity) {
31199
+ costTracker.add(capacity);
31200
+ }
31201
+ } else {
31202
+ costTracker.add(batchGetResult.ConsumedCapacity);
31203
+ }
31027
31204
  const existingItems = batchGetResult.Responses?.[tableName] || [];
31028
31205
  const existingIds = /* @__PURE__ */ new Set();
31029
31206
  const preparedRecords = [];
@@ -31067,7 +31244,8 @@ async function handleDeleteMany(resource, params, requestId) {
31067
31244
  count: 0,
31068
31245
  successIds: {},
31069
31246
  failedIds: failedIdsMap2,
31070
- errors: errorsMap2
31247
+ errors: errorsMap2,
31248
+ consumedCapacity: costTracker.getAggregated()
31071
31249
  };
31072
31250
  }
31073
31251
  const getItemCount = /* @__PURE__ */ __name((record) => {
@@ -31106,14 +31284,22 @@ async function handleDeleteMany(resource, params, requestId) {
31106
31284
  });
31107
31285
  }
31108
31286
  }
31109
- await executeDynamoDBOperation(
31287
+ const result = await executeDynamoDBOperation(
31110
31288
  () => dbClient2.send(
31111
31289
  new import_lib_dynamodb5.TransactWriteCommand({
31112
- TransactItems: transactItems
31290
+ TransactItems: transactItems,
31291
+ ReturnConsumedCapacity: "TOTAL"
31113
31292
  })
31114
31293
  ),
31115
31294
  "TransactWriteItems"
31116
31295
  );
31296
+ if (Array.isArray(result.ConsumedCapacity)) {
31297
+ for (const capacity of result.ConsumedCapacity) {
31298
+ costTracker.add(capacity);
31299
+ }
31300
+ } else {
31301
+ costTracker.add(result.ConsumedCapacity);
31302
+ }
31117
31303
  return chunk;
31118
31304
  }, "executeChunk");
31119
31305
  const {
@@ -31191,7 +31377,8 @@ async function handleDeleteMany(resource, params, requestId) {
31191
31377
  count,
31192
31378
  successIds,
31193
31379
  failedIds: failedIdsMap,
31194
- errors: errorsMap
31380
+ errors: errorsMap,
31381
+ consumedCapacity: costTracker.getAggregated()
31195
31382
  };
31196
31383
  }
31197
31384
  var import_lib_dynamodb5, logger10;
@@ -31203,6 +31390,7 @@ var init_deleteMany = __esm({
31203
31390
  init_shadow();
31204
31391
  init_bulkOperations();
31205
31392
  init_chunking();
31393
+ init_cost_tracker();
31206
31394
  init_dynamodb3();
31207
31395
  logger10 = createLogger({ service: "records-lambda" });
31208
31396
  __name(handleDeleteMany, "handleDeleteMany");
@@ -31448,6 +31636,7 @@ __export(insertMany_exports, {
31448
31636
  async function handleInsertMany(resource, params, requestId) {
31449
31637
  const { data: recordsData } = params;
31450
31638
  const startTime = Date.now();
31639
+ const costTracker = new CostTracker();
31451
31640
  logger16.debug("Executing insertMany", {
31452
31641
  requestId,
31453
31642
  resource,
@@ -31458,7 +31647,8 @@ async function handleInsertMany(resource, params, requestId) {
31458
31647
  count: 0,
31459
31648
  successIds: {},
31460
31649
  failedIds: {},
31461
- errors: {}
31650
+ errors: {},
31651
+ consumedCapacity: costTracker.getAggregated()
31462
31652
  };
31463
31653
  }
31464
31654
  logLargeBatchWarning("insertMany", recordsData.length, requestId, resource);
@@ -31546,14 +31736,22 @@ async function handleInsertMany(resource, params, requestId) {
31546
31736
  });
31547
31737
  }
31548
31738
  }
31549
- await executeDynamoDBOperation(
31739
+ const result = await executeDynamoDBOperation(
31550
31740
  () => dbClient2.send(
31551
31741
  new import_lib_dynamodb8.TransactWriteCommand({
31552
- TransactItems: transactItems
31742
+ TransactItems: transactItems,
31743
+ ReturnConsumedCapacity: "TOTAL"
31553
31744
  })
31554
31745
  ),
31555
31746
  "TransactWriteItems"
31556
31747
  );
31748
+ if (Array.isArray(result.ConsumedCapacity)) {
31749
+ for (const capacity of result.ConsumedCapacity) {
31750
+ costTracker.add(capacity);
31751
+ }
31752
+ } else {
31753
+ costTracker.add(result.ConsumedCapacity);
31754
+ }
31557
31755
  return chunk;
31558
31756
  }, "executeChunk");
31559
31757
  const {
@@ -31632,7 +31830,8 @@ async function handleInsertMany(resource, params, requestId) {
31632
31830
  count,
31633
31831
  successIds,
31634
31832
  failedIds: failedIdsMap,
31635
- errors: errorsMap
31833
+ errors: errorsMap,
31834
+ consumedCapacity: costTracker.getAggregated()
31636
31835
  };
31637
31836
  }
31638
31837
  function getPreparationErrorCode(error2) {
@@ -31656,6 +31855,7 @@ var init_insertMany = __esm({
31656
31855
  init_shadow();
31657
31856
  init_bulkOperations();
31658
31857
  init_chunking();
31858
+ init_cost_tracker();
31659
31859
  init_dynamodb3();
31660
31860
  init_timestamps();
31661
31861
  init_ttl();
@@ -31714,6 +31914,7 @@ async function handleUpdateMany(resource, params, requestId) {
31714
31914
  const { data: patchData, options } = params;
31715
31915
  const upsert = options?.upsert ?? false;
31716
31916
  const startTime = Date.now();
31917
+ const costTracker = new CostTracker();
31717
31918
  logger18.debug("Executing updateMany", {
31718
31919
  requestId,
31719
31920
  resource,
@@ -31767,7 +31968,8 @@ async function handleUpdateMany(resource, params, requestId) {
31767
31968
  count: 0,
31768
31969
  successIds: {},
31769
31970
  failedIds: {},
31770
- errors: {}
31971
+ errors: {},
31972
+ consumedCapacity: costTracker.getAggregated()
31771
31973
  };
31772
31974
  }
31773
31975
  }
@@ -31787,11 +31989,19 @@ async function handleUpdateMany(resource, params, requestId) {
31787
31989
  Keys: keys,
31788
31990
  ConsistentRead: true
31789
31991
  }
31790
- }
31992
+ },
31993
+ ReturnConsumedCapacity: "TOTAL"
31791
31994
  })
31792
31995
  ),
31793
31996
  "BatchGetItem"
31794
31997
  );
31998
+ if (Array.isArray(batchGetResult.ConsumedCapacity)) {
31999
+ for (const capacity of batchGetResult.ConsumedCapacity) {
32000
+ costTracker.add(capacity);
32001
+ }
32002
+ } else {
32003
+ costTracker.add(batchGetResult.ConsumedCapacity);
32004
+ }
31795
32005
  const existingItems = batchGetResult.Responses?.[tableName] || [];
31796
32006
  const existingIds = new Set(
31797
32007
  existingItems.map((item) => {
@@ -31957,14 +32167,22 @@ async function handleUpdateMany(resource, params, requestId) {
31957
32167
  });
31958
32168
  }
31959
32169
  }
31960
- await executeDynamoDBOperation(
32170
+ const result = await executeDynamoDBOperation(
31961
32171
  () => dbClient2.send(
31962
32172
  new import_lib_dynamodb9.TransactWriteCommand({
31963
- TransactItems: transactItems
32173
+ TransactItems: transactItems,
32174
+ ReturnConsumedCapacity: "TOTAL"
31964
32175
  })
31965
32176
  ),
31966
32177
  "TransactWriteItems"
31967
32178
  );
32179
+ if (Array.isArray(result.ConsumedCapacity)) {
32180
+ for (const capacity of result.ConsumedCapacity) {
32181
+ costTracker.add(capacity);
32182
+ }
32183
+ } else {
32184
+ costTracker.add(result.ConsumedCapacity);
32185
+ }
31968
32186
  return chunk;
31969
32187
  }, "executeChunk");
31970
32188
  const {
@@ -32077,8 +32295,9 @@ async function handleUpdateMany(resource, params, requestId) {
32077
32295
  successIds,
32078
32296
  failedIds: failedIdsMap,
32079
32297
  errors: errorsMap,
32080
- items
32298
+ items,
32081
32299
  // 更新したフィールドのみを含むレコード配列(ADR 001)
32300
+ consumedCapacity: costTracker.getAggregated()
32082
32301
  };
32083
32302
  }
32084
32303
  function getPreparationErrorCode2(error2) {
@@ -32102,6 +32321,7 @@ var init_updateMany = __esm({
32102
32321
  init_shadow();
32103
32322
  init_bulkOperations();
32104
32323
  init_chunking();
32324
+ init_cost_tracker();
32105
32325
  init_dynamodb3();
32106
32326
  init_timestamps();
32107
32327
  logger18 = createLogger({ service: "records-lambda" });
@@ -32153,7 +32373,10 @@ async function handleDeleteOne(resource, params, requestId) {
32153
32373
  throw new Error(`Failed to delete record: ${targetId}`);
32154
32374
  }
32155
32375
  }
32156
- return { id: targetId };
32376
+ return {
32377
+ id: targetId,
32378
+ consumedCapacity: deleteManyResult.consumedCapacity
32379
+ };
32157
32380
  } else {
32158
32381
  logger11.debug("Executing deleteOne with filter", {
32159
32382
  requestId,
@@ -32184,7 +32407,10 @@ async function handleDeleteOne(resource, params, requestId) {
32184
32407
  resource,
32185
32408
  id: deletedId
32186
32409
  });
32187
- return { id: deletedId };
32410
+ return {
32411
+ id: deletedId,
32412
+ consumedCapacity: deleteManyResult.consumedCapacity
32413
+ };
32188
32414
  }
32189
32415
  }
32190
32416
  __name(handleDeleteOne, "handleDeleteOne");
@@ -32351,7 +32577,10 @@ async function handleInsertOne(resource, params, requestId) {
32351
32577
  resource,
32352
32578
  id: createdId
32353
32579
  });
32354
- return createdRecord;
32580
+ return {
32581
+ ...createdRecord,
32582
+ consumedCapacity: insertManyResult.consumedCapacity
32583
+ };
32355
32584
  }
32356
32585
  __name(handleInsertOne, "handleInsertOne");
32357
32586
 
@@ -32392,7 +32621,10 @@ async function handleUpdateOne(resource, params, requestId) {
32392
32621
  if (!updateManyResult.items || updateManyResult.items.length === 0) {
32393
32622
  throw new Error("updateMany did not return items");
32394
32623
  }
32395
- return updateManyResult.items[0];
32624
+ return {
32625
+ ...updateManyResult.items[0],
32626
+ consumedCapacity: updateManyResult.consumedCapacity
32627
+ };
32396
32628
  } else {
32397
32629
  logger19.debug("Executing updateOne with filter", {
32398
32630
  requestId,
@@ -32420,7 +32652,10 @@ async function handleUpdateOne(resource, params, requestId) {
32420
32652
  if (!updateManyResult.items || updateManyResult.items.length === 0) {
32421
32653
  throw new Error("updateMany did not return items");
32422
32654
  }
32423
- return updateManyResult.items[0];
32655
+ return {
32656
+ ...updateManyResult.items[0],
32657
+ consumedCapacity: updateManyResult.consumedCapacity
32658
+ };
32424
32659
  }
32425
32660
  }
32426
32661
  __name(handleUpdateOne, "handleUpdateOne");
@@ -34045,7 +34280,7 @@ async function handler(event) {
34045
34280
  return createCorsResponse(HTTP_STATUS.OK);
34046
34281
  }
34047
34282
  if (event.requestContext.http.method === "GET" && event.requestContext.http.path === "/version") {
34048
- const version = "1.3.42";
34283
+ const version = "1.3.44";
34049
34284
  return createSuccessResponse({ version, timestamp: (/* @__PURE__ */ new Date()).toISOString() }, requestId);
34050
34285
  }
34051
34286
  if (event.requestContext.http.method !== "POST") {