@exabugs/dynamodb-client 1.6.2 → 1.8.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/scripts/operations/bulkRecordRepair.js +2 -1
  3. package/dist/scripts/operations/bulkRecordRepair.js.map +1 -1
  4. package/dist/server/handler.cjs +174 -76
  5. package/dist/server/handler.cjs.map +4 -4
  6. package/dist/server/media-handler.cjs +2 -2
  7. package/dist/server/media-process-handler-dlq.cjs +179 -81
  8. package/dist/server/media-process-handler-dlq.cjs.map +4 -4
  9. package/dist/server/media-process-handler.cjs +179 -81
  10. package/dist/server/media-process-handler.cjs.map +4 -4
  11. package/dist/server/operations/find/idQuery.d.ts.map +1 -1
  12. package/dist/server/operations/find/idQuery.js +57 -39
  13. package/dist/server/operations/find/idQuery.js.map +1 -1
  14. package/dist/server/operations/find/utils.js +2 -2
  15. package/dist/server/operations/find/utils.js.map +1 -1
  16. package/dist/server/operations/updateMany.d.ts.map +1 -1
  17. package/dist/server/operations/updateMany.js +6 -76
  18. package/dist/server/operations/updateMany.js.map +1 -1
  19. package/dist/server/operations/updateOne.d.ts.map +1 -1
  20. package/dist/server/operations/updateOne.js +9 -1
  21. package/dist/server/operations/updateOne.js.map +1 -1
  22. package/dist/server/utils/mergePatch.d.ts +8 -0
  23. package/dist/server/utils/mergePatch.d.ts.map +1 -0
  24. package/dist/server/utils/mergePatch.js +127 -0
  25. package/dist/server/utils/mergePatch.js.map +1 -0
  26. package/dist/server/utils/timestamps.d.ts.map +1 -1
  27. package/dist/server/utils/timestamps.js +2 -1
  28. package/dist/server/utils/timestamps.js.map +1 -1
  29. package/dist/sharp-layer.zip +0 -0
  30. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- // @exabugs/dynamodb-client v1.6.2
2
- // Built: 2026-10-11T14:15:49.129Z
1
+ // @exabugs/dynamodb-client v1.8.0
2
+ // Built: 2026-10-11T23:03:45.636Z
3
3
  "use strict";
4
4
  var __create = Object.create;
5
5
  var __defProp = Object.defineProperty;
@@ -1,5 +1,5 @@
1
- // @exabugs/dynamodb-client v1.6.2
2
- // Built: 2026-10-11T14:15:49.129Z
1
+ // @exabugs/dynamodb-client v1.8.0
2
+ // Built: 2026-10-11T23:03:45.636Z
3
3
  "use strict";
4
4
  var __create = Object.create;
5
5
  var __defProp = Object.defineProperty;
@@ -37714,7 +37714,7 @@ var init_types2 = __esm({
37714
37714
  });
37715
37715
 
37716
37716
  // src/shared/errors/index.ts
37717
- var AppError, ConfigError, InvalidTokenError;
37717
+ var AppError, ConfigError, InvalidFilterError, InvalidTokenError;
37718
37718
  var init_errors4 = __esm({
37719
37719
  "src/shared/errors/index.ts"() {
37720
37720
  "use strict";
@@ -37750,6 +37750,14 @@ var init_errors4 = __esm({
37750
37750
  super("CONFIG_ERROR" /* CONFIG_ERROR */, message, 500, details);
37751
37751
  }
37752
37752
  };
37753
+ InvalidFilterError = class extends AppError {
37754
+ static {
37755
+ __name(this, "InvalidFilterError");
37756
+ }
37757
+ constructor(message, details) {
37758
+ super("INVALID_FILTER" /* INVALID_FILTER */, message, 400, details);
37759
+ }
37760
+ };
37753
37761
  InvalidTokenError = class extends AppError {
37754
37762
  static {
37755
37763
  __name(this, "InvalidTokenError");
@@ -46087,7 +46095,7 @@ function parseFilters(filter) {
46087
46095
  fieldKey,
46088
46096
  error: error2 instanceof Error ? error2.message : String(error2)
46089
46097
  });
46090
- throw new ConfigError(`Invalid filter field syntax: ${fieldKey}`, {
46098
+ throw new InvalidFilterError(`Invalid filter field syntax: ${fieldKey}`, {
46091
46099
  field: fieldKey,
46092
46100
  error: error2 instanceof Error ? error2.message : String(error2)
46093
46101
  });
@@ -46279,7 +46287,14 @@ async function executeInQuery(resource, targetIds, sort, requestId) {
46279
46287
  }
46280
46288
  async function executeAllRecordsQuery(resource, sort, perPage, nextToken, parsedFilters, requestId) {
46281
46289
  if (parsedFilters.length > 0) {
46282
- return executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken, parsedFilters, requestId);
46290
+ return executeAllRecordsQueryFullScan(
46291
+ resource,
46292
+ sort,
46293
+ perPage,
46294
+ nextToken,
46295
+ parsedFilters,
46296
+ requestId
46297
+ );
46283
46298
  }
46284
46299
  const dbClient2 = getDBClient();
46285
46300
  const tableName = getTableName();
@@ -46351,19 +46366,20 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
46351
46366
  const dbClient2 = getDBClient();
46352
46367
  const tableName = getTableName();
46353
46368
  const costTracker = new CostTracker();
46354
- const offset = nextToken ? decodeOffsetToken(nextToken) ?? 0 : 0;
46355
- logger4.debug("Executing full scan query (ID sort)", {
46356
- requestId,
46357
- resource,
46358
- offset
46359
- });
46360
- const allRecords = [];
46361
46369
  let exclusiveStartKey;
46362
- let previousKeySignature;
46363
- const MAX_ITERATIONS = 1e4;
46370
+ if (nextToken) {
46371
+ const decoded = decodeNextToken(nextToken);
46372
+ exclusiveStartKey = { PK: decoded.PK, SK: decoded.SK };
46373
+ }
46374
+ const page = [];
46375
+ let lastReturned;
46376
+ let hasNextPage = false;
46377
+ let scanned = 0;
46364
46378
  let iterations = 0;
46365
- do {
46366
- if (++iterations > MAX_ITERATIONS) {
46379
+ let previousKeySignature;
46380
+ let chunkSize = SCAN_CHUNK_INITIAL;
46381
+ scan: while (true) {
46382
+ if (++iterations > SCAN_MAX_ITERATIONS) {
46367
46383
  logger4.error("executeAllRecordsQueryFullScan: \u6700\u5927\u53CD\u5FA9\u56DE\u6570\u3092\u8D85\u904E\u3057\u305F\u305F\u3081\u4E2D\u65AD", {
46368
46384
  requestId,
46369
46385
  resource,
@@ -46381,8 +46397,7 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
46381
46397
  ":skPrefix": "id#"
46382
46398
  },
46383
46399
  ScanIndexForward: sort.order === "ASC",
46384
- Limit: 1e3,
46385
- // 大きめの Limit でループ回数を最小化
46400
+ Limit: chunkSize,
46386
46401
  ExclusiveStartKey: exclusiveStartKey,
46387
46402
  ConsistentRead: true,
46388
46403
  ReturnConsumedCapacity: "TOTAL"
@@ -46391,10 +46406,24 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
46391
46406
  "Query"
46392
46407
  );
46393
46408
  costTracker.add(queryResult.ConsumedCapacity);
46394
- allRecords.push(...queryResult.Items || []);
46409
+ for (const row of queryResult.Items || []) {
46410
+ scanned++;
46411
+ if (!matchesAllFilters(extractCleanRecord(row), parsedFilters)) {
46412
+ continue;
46413
+ }
46414
+ if (page.length >= perPage) {
46415
+ hasNextPage = true;
46416
+ break scan;
46417
+ }
46418
+ page.push(extractCleanRecord(row));
46419
+ lastReturned = { PK: row.PK, SK: row.SK };
46420
+ }
46395
46421
  const nextKey = queryResult.LastEvaluatedKey;
46396
- const nextKeySignature = nextKey ? `${nextKey.PK}#${nextKey.SK}` : void 0;
46397
- if (nextKeySignature && nextKeySignature === previousKeySignature) {
46422
+ if (!nextKey) {
46423
+ break;
46424
+ }
46425
+ const nextKeySignature = `${nextKey.PK}#${nextKey.SK}`;
46426
+ if (nextKeySignature === previousKeySignature) {
46398
46427
  logger4.error("executeAllRecordsQueryFullScan: \u540C\u4E00\u306ELastEvaluatedKey\u304C\u8FD4\u5374\u3055\u308C\u305F\u305F\u3081\u4E2D\u65AD", {
46399
46428
  requestId,
46400
46429
  resource,
@@ -46404,28 +46433,24 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
46404
46433
  }
46405
46434
  previousKeySignature = nextKeySignature;
46406
46435
  exclusiveStartKey = nextKey;
46407
- } while (exclusiveStartKey);
46408
- let items = allRecords.map((item) => extractCleanRecord(item));
46409
- items = items.filter((record) => matchesAllFilters(record, parsedFilters));
46410
- const page = items.slice(offset, offset + perPage);
46411
- const hasNextPage = offset + perPage < items.length;
46412
- const nextTokenValue = hasNextPage ? encodeOffsetToken(offset + perPage) : void 0;
46413
- logger4.info("ID full scan query succeeded", {
46436
+ chunkSize = Math.min(chunkSize * 2, SCAN_CHUNK_MAX);
46437
+ }
46438
+ const nextTokenValue = hasNextPage && lastReturned ? encodeNextToken(lastReturned.PK, lastReturned.SK) : void 0;
46439
+ logger4.info("ID filtered scan query succeeded", {
46414
46440
  requestId,
46415
46441
  resource,
46416
- totalMatched: items.length,
46417
- offset,
46442
+ scanned,
46418
46443
  returned: page.length,
46419
46444
  hasNextPage
46420
46445
  });
46421
46446
  return {
46422
46447
  items: page,
46423
- pageInfo: { hasNextPage, hasPreviousPage: offset > 0 },
46448
+ pageInfo: { hasNextPage, hasPreviousPage: !!nextToken },
46424
46449
  ...nextTokenValue && { nextToken: nextTokenValue },
46425
46450
  consumedCapacity: costTracker.getAggregated()
46426
46451
  };
46427
46452
  }
46428
- var import_lib_dynamodb2, logger4;
46453
+ var import_lib_dynamodb2, logger4, SCAN_CHUNK_INITIAL, SCAN_CHUNK_MAX, SCAN_MAX_ITERATIONS;
46429
46454
  var init_idQuery = __esm({
46430
46455
  "src/server/operations/find/idQuery.ts"() {
46431
46456
  "use strict";
@@ -46443,6 +46468,9 @@ var init_idQuery = __esm({
46443
46468
  __name(executeSpecificIdQuery, "executeSpecificIdQuery");
46444
46469
  __name(executeInQuery, "executeInQuery");
46445
46470
  __name(executeAllRecordsQuery, "executeAllRecordsQuery");
46471
+ SCAN_CHUNK_INITIAL = 100;
46472
+ SCAN_CHUNK_MAX = 1e3;
46473
+ SCAN_MAX_ITERATIONS = 1e4;
46446
46474
  __name(executeAllRecordsQueryFullScan, "executeAllRecordsQueryFullScan");
46447
46475
  }
46448
46476
  });
@@ -47347,6 +47375,113 @@ var init_chunking = __esm({
47347
47375
  }
47348
47376
  });
47349
47377
 
47378
+ // src/server/utils/mergePatch.ts
47379
+ function isPlainObject(value) {
47380
+ return typeof value === "object" && value !== null && !Array.isArray(value);
47381
+ }
47382
+ function invalidPath(path, reason) {
47383
+ return new AppError("VALIDATION_ERROR" /* VALIDATION_ERROR */, `Invalid patch path "${path}": ${reason}`, 400, {
47384
+ path
47385
+ });
47386
+ }
47387
+ function mergeInto(target, patch) {
47388
+ for (const [key, value] of Object.entries(patch)) {
47389
+ if (key.includes(".")) {
47390
+ setByPath(target, key, value);
47391
+ } else {
47392
+ setKey(target, key, value, key);
47393
+ }
47394
+ }
47395
+ }
47396
+ function setKey(target, key, value, path) {
47397
+ if (key === "__proto__") {
47398
+ throw invalidPath(path, "forbidden segment");
47399
+ }
47400
+ if (value === null) {
47401
+ delete target[key];
47402
+ } else if (isPlainObject(value) && isPlainObject(target[key])) {
47403
+ mergeInto(target[key], value);
47404
+ } else {
47405
+ target[key] = value;
47406
+ }
47407
+ }
47408
+ function setByPath(target, path, value) {
47409
+ const keys = path.split(".");
47410
+ if (keys.some((k4) => k4 === "")) {
47411
+ throw invalidPath(path, "empty segment");
47412
+ }
47413
+ let current = target;
47414
+ for (let i4 = 0; i4 < keys.length; i4++) {
47415
+ const key = keys[i4];
47416
+ const isLast = i4 === keys.length - 1;
47417
+ if (Array.isArray(current)) {
47418
+ if (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= current.length) {
47419
+ throw invalidPath(path, `"${key}" is not a valid index (length ${current.length})`);
47420
+ }
47421
+ const index = Number(key);
47422
+ if (isLast) {
47423
+ if (value === null) {
47424
+ throw invalidPath(path, "array elements cannot be deleted by path");
47425
+ }
47426
+ const existing = current[index];
47427
+ if (isPlainObject(value) && isPlainObject(existing)) {
47428
+ mergeInto(existing, value);
47429
+ } else {
47430
+ current[index] = value;
47431
+ }
47432
+ return;
47433
+ }
47434
+ const next2 = current[index];
47435
+ if (isPlainObject(next2) || Array.isArray(next2)) {
47436
+ current = next2;
47437
+ } else {
47438
+ if (value === null) {
47439
+ return;
47440
+ }
47441
+ const created = {};
47442
+ current[index] = created;
47443
+ current = created;
47444
+ }
47445
+ continue;
47446
+ }
47447
+ if (isLast) {
47448
+ setKey(current, key, value, path);
47449
+ return;
47450
+ }
47451
+ if (key === "__proto__") {
47452
+ throw invalidPath(path, "forbidden segment");
47453
+ }
47454
+ const next = current[key];
47455
+ if (isPlainObject(next) || Array.isArray(next)) {
47456
+ current = next;
47457
+ } else {
47458
+ if (value === null) {
47459
+ return;
47460
+ }
47461
+ const created = {};
47462
+ current[key] = created;
47463
+ current = created;
47464
+ }
47465
+ }
47466
+ }
47467
+ function applyJsonMergePatch(target, patch) {
47468
+ const result = structuredClone(target);
47469
+ mergeInto(result, structuredClone(patch));
47470
+ return result;
47471
+ }
47472
+ var init_mergePatch = __esm({
47473
+ "src/server/utils/mergePatch.ts"() {
47474
+ "use strict";
47475
+ init_shared();
47476
+ __name(isPlainObject, "isPlainObject");
47477
+ __name(invalidPath, "invalidPath");
47478
+ __name(mergeInto, "mergeInto");
47479
+ __name(setKey, "setKey");
47480
+ __name(setByPath, "setByPath");
47481
+ __name(applyJsonMergePatch, "applyJsonMergePatch");
47482
+ }
47483
+ });
47484
+
47350
47485
  // src/server/utils/timestamps.ts
47351
47486
  var timestamps_exports = {};
47352
47487
  __export(timestamps_exports, {
@@ -47380,8 +47515,8 @@ function addUpdateTimestamp(data) {
47380
47515
  }
47381
47516
  const now = (/* @__PURE__ */ new Date()).toISOString();
47382
47517
  return {
47383
- [timestampFields.updatedAt]: now,
47384
- ...data
47518
+ ...data,
47519
+ [timestampFields.updatedAt]: data[timestampFields.updatedAt] ?? now
47385
47520
  };
47386
47521
  }
47387
47522
  var init_timestamps = __esm({
@@ -47399,46 +47534,6 @@ var updateMany_exports = {};
47399
47534
  __export(updateMany_exports, {
47400
47535
  handleUpdateMany: () => handleUpdateMany
47401
47536
  });
47402
- function expandDotNotation(patch) {
47403
- const result = {};
47404
- for (const [key, value] of Object.entries(patch)) {
47405
- if (key.includes(".")) {
47406
- const keys = key.split(".");
47407
- let current = result;
47408
- for (let i4 = 0; i4 < keys.length - 1; i4++) {
47409
- const k4 = keys[i4];
47410
- if (!(k4 in current)) {
47411
- current[k4] = {};
47412
- } else if (typeof current[k4] !== "object" || Array.isArray(current[k4])) {
47413
- current[k4] = {};
47414
- }
47415
- current = current[k4];
47416
- }
47417
- const lastKey = keys[keys.length - 1];
47418
- current[lastKey] = value;
47419
- } else {
47420
- result[key] = value;
47421
- }
47422
- }
47423
- return result;
47424
- }
47425
- function applyJsonMergePatch(target, patch) {
47426
- const expandedPatch = expandDotNotation(patch);
47427
- const result = { ...target };
47428
- for (const [key, value] of Object.entries(expandedPatch)) {
47429
- if (value === null) {
47430
- delete result[key];
47431
- } else if (typeof value === "object" && !Array.isArray(value) && value !== null && typeof result[key] === "object" && !Array.isArray(result[key]) && result[key] !== null) {
47432
- result[key] = applyJsonMergePatch(
47433
- result[key],
47434
- value
47435
- );
47436
- } else {
47437
- result[key] = value;
47438
- }
47439
- }
47440
- return result;
47441
- }
47442
47537
  async function handleUpdateMany(resource, params, requestId) {
47443
47538
  const { data: patchData, options } = params;
47444
47539
  const upsert = options?.upsert ?? false;
@@ -47566,11 +47661,9 @@ async function handleUpdateMany(resource, params, requestId) {
47566
47661
  const id = existingData.id;
47567
47662
  const oldShadowKeys = item.__shadowKeys ?? existingData.__shadowKeys ?? [];
47568
47663
  const actualPatchData2 = patchData.$set ? patchData.$set : patchData;
47569
- const mergedData = applyJsonMergePatch(removeShadowKeys(existingData), actualPatchData2);
47570
- const updatedData = addUpdateTimestamp({
47571
- ...mergedData,
47572
- id
47573
- });
47664
+ const timestampedPatch = addUpdateTimestamp(actualPatchData2);
47665
+ const mergedData = applyJsonMergePatch(removeShadowKeys(existingData), timestampedPatch);
47666
+ const updatedData = { ...mergedData, id };
47574
47667
  const newShadowRecords = generateShadowRecords(updatedData, resource, shadowConfig);
47575
47668
  const newShadowKeys = newShadowRecords.map((shadow) => shadow.SK);
47576
47669
  const mainSK = generateMainRecordSK2(id);
@@ -47851,10 +47944,9 @@ var init_updateMany = __esm({
47851
47944
  init_chunking();
47852
47945
  init_cost_tracker();
47853
47946
  init_dynamodb3();
47947
+ init_mergePatch();
47854
47948
  init_timestamps();
47855
47949
  logger11 = createLogger({ service: "records-lambda" });
47856
- __name(expandDotNotation, "expandDotNotation");
47857
- __name(applyJsonMergePatch, "applyJsonMergePatch");
47858
47950
  __name(handleUpdateMany, "handleUpdateMany");
47859
47951
  __name(getPreparationErrorCode, "getPreparationErrorCode");
47860
47952
  }
@@ -47990,6 +48082,9 @@ async function handleUpdateOne(resource, params, requestId) {
47990
48082
  if (updateManyResult.count === 0) {
47991
48083
  const error2 = Object.values(updateManyResult.errors || {})[0];
47992
48084
  if (error2) {
48085
+ if (error2.code === "VALIDATION_ERROR" /* VALIDATION_ERROR */) {
48086
+ throw new AppError("VALIDATION_ERROR" /* VALIDATION_ERROR */, error2.message ?? "Invalid patch", 400);
48087
+ }
47993
48088
  throw new Error(`Failed to update record: ${error2.message}`);
47994
48089
  } else {
47995
48090
  throw new Error(`Failed to update record: ${targetId}`);
@@ -48029,6 +48124,9 @@ async function handleUpdateOne(resource, params, requestId) {
48029
48124
  if (updateManyResult.count === 0) {
48030
48125
  const error2 = Object.values(updateManyResult.errors || {})[0];
48031
48126
  if (error2) {
48127
+ if (error2.code === "VALIDATION_ERROR" /* VALIDATION_ERROR */) {
48128
+ throw new AppError("VALIDATION_ERROR" /* VALIDATION_ERROR */, error2.message ?? "Invalid patch", 400);
48129
+ }
48032
48130
  throw new Error(`Failed to update record: ${error2.message}`);
48033
48131
  } else {
48034
48132
  throw new Error(`No records found matching filter`);