@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;
@@ -50105,7 +50105,7 @@ var init_types2 = __esm({
50105
50105
  });
50106
50106
 
50107
50107
  // src/shared/errors/index.ts
50108
- var AppError, ConfigError, InvalidTokenError;
50108
+ var AppError, ConfigError, InvalidFilterError, InvalidTokenError;
50109
50109
  var init_errors4 = __esm({
50110
50110
  "src/shared/errors/index.ts"() {
50111
50111
  "use strict";
@@ -50141,6 +50141,14 @@ var init_errors4 = __esm({
50141
50141
  super("CONFIG_ERROR" /* CONFIG_ERROR */, message, 500, details);
50142
50142
  }
50143
50143
  };
50144
+ InvalidFilterError = class extends AppError {
50145
+ static {
50146
+ __name(this, "InvalidFilterError");
50147
+ }
50148
+ constructor(message, details) {
50149
+ super("INVALID_FILTER" /* INVALID_FILTER */, message, 400, details);
50150
+ }
50151
+ };
50144
50152
  InvalidTokenError = class extends AppError {
50145
50153
  static {
50146
50154
  __name(this, "InvalidTokenError");
@@ -58478,7 +58486,7 @@ function parseFilters(filter) {
58478
58486
  fieldKey,
58479
58487
  error: error2 instanceof Error ? error2.message : String(error2)
58480
58488
  });
58481
- throw new ConfigError(`Invalid filter field syntax: ${fieldKey}`, {
58489
+ throw new InvalidFilterError(`Invalid filter field syntax: ${fieldKey}`, {
58482
58490
  field: fieldKey,
58483
58491
  error: error2 instanceof Error ? error2.message : String(error2)
58484
58492
  });
@@ -58670,7 +58678,14 @@ async function executeInQuery(resource, targetIds, sort, requestId) {
58670
58678
  }
58671
58679
  async function executeAllRecordsQuery(resource, sort, perPage, nextToken, parsedFilters, requestId) {
58672
58680
  if (parsedFilters.length > 0) {
58673
- return executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken, parsedFilters, requestId);
58681
+ return executeAllRecordsQueryFullScan(
58682
+ resource,
58683
+ sort,
58684
+ perPage,
58685
+ nextToken,
58686
+ parsedFilters,
58687
+ requestId
58688
+ );
58674
58689
  }
58675
58690
  const dbClient2 = getDBClient();
58676
58691
  const tableName = getTableName();
@@ -58742,19 +58757,20 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
58742
58757
  const dbClient2 = getDBClient();
58743
58758
  const tableName = getTableName();
58744
58759
  const costTracker = new CostTracker();
58745
- const offset = nextToken ? decodeOffsetToken(nextToken) ?? 0 : 0;
58746
- logger4.debug("Executing full scan query (ID sort)", {
58747
- requestId,
58748
- resource,
58749
- offset
58750
- });
58751
- const allRecords = [];
58752
58760
  let exclusiveStartKey;
58753
- let previousKeySignature;
58754
- const MAX_ITERATIONS = 1e4;
58761
+ if (nextToken) {
58762
+ const decoded = decodeNextToken(nextToken);
58763
+ exclusiveStartKey = { PK: decoded.PK, SK: decoded.SK };
58764
+ }
58765
+ const page = [];
58766
+ let lastReturned;
58767
+ let hasNextPage = false;
58768
+ let scanned = 0;
58755
58769
  let iterations = 0;
58756
- do {
58757
- if (++iterations > MAX_ITERATIONS) {
58770
+ let previousKeySignature;
58771
+ let chunkSize = SCAN_CHUNK_INITIAL;
58772
+ scan: while (true) {
58773
+ if (++iterations > SCAN_MAX_ITERATIONS) {
58758
58774
  logger4.error("executeAllRecordsQueryFullScan: \u6700\u5927\u53CD\u5FA9\u56DE\u6570\u3092\u8D85\u904E\u3057\u305F\u305F\u3081\u4E2D\u65AD", {
58759
58775
  requestId,
58760
58776
  resource,
@@ -58772,8 +58788,7 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
58772
58788
  ":skPrefix": "id#"
58773
58789
  },
58774
58790
  ScanIndexForward: sort.order === "ASC",
58775
- Limit: 1e3,
58776
- // 大きめの Limit でループ回数を最小化
58791
+ Limit: chunkSize,
58777
58792
  ExclusiveStartKey: exclusiveStartKey,
58778
58793
  ConsistentRead: true,
58779
58794
  ReturnConsumedCapacity: "TOTAL"
@@ -58782,10 +58797,24 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
58782
58797
  "Query"
58783
58798
  );
58784
58799
  costTracker.add(queryResult.ConsumedCapacity);
58785
- allRecords.push(...queryResult.Items || []);
58800
+ for (const row of queryResult.Items || []) {
58801
+ scanned++;
58802
+ if (!matchesAllFilters(extractCleanRecord(row), parsedFilters)) {
58803
+ continue;
58804
+ }
58805
+ if (page.length >= perPage) {
58806
+ hasNextPage = true;
58807
+ break scan;
58808
+ }
58809
+ page.push(extractCleanRecord(row));
58810
+ lastReturned = { PK: row.PK, SK: row.SK };
58811
+ }
58786
58812
  const nextKey = queryResult.LastEvaluatedKey;
58787
- const nextKeySignature = nextKey ? `${nextKey.PK}#${nextKey.SK}` : void 0;
58788
- if (nextKeySignature && nextKeySignature === previousKeySignature) {
58813
+ if (!nextKey) {
58814
+ break;
58815
+ }
58816
+ const nextKeySignature = `${nextKey.PK}#${nextKey.SK}`;
58817
+ if (nextKeySignature === previousKeySignature) {
58789
58818
  logger4.error("executeAllRecordsQueryFullScan: \u540C\u4E00\u306ELastEvaluatedKey\u304C\u8FD4\u5374\u3055\u308C\u305F\u305F\u3081\u4E2D\u65AD", {
58790
58819
  requestId,
58791
58820
  resource,
@@ -58795,28 +58824,24 @@ async function executeAllRecordsQueryFullScan(resource, sort, perPage, nextToken
58795
58824
  }
58796
58825
  previousKeySignature = nextKeySignature;
58797
58826
  exclusiveStartKey = nextKey;
58798
- } while (exclusiveStartKey);
58799
- let items = allRecords.map((item) => extractCleanRecord(item));
58800
- items = items.filter((record) => matchesAllFilters(record, parsedFilters));
58801
- const page = items.slice(offset, offset + perPage);
58802
- const hasNextPage = offset + perPage < items.length;
58803
- const nextTokenValue = hasNextPage ? encodeOffsetToken(offset + perPage) : void 0;
58804
- logger4.info("ID full scan query succeeded", {
58827
+ chunkSize = Math.min(chunkSize * 2, SCAN_CHUNK_MAX);
58828
+ }
58829
+ const nextTokenValue = hasNextPage && lastReturned ? encodeNextToken(lastReturned.PK, lastReturned.SK) : void 0;
58830
+ logger4.info("ID filtered scan query succeeded", {
58805
58831
  requestId,
58806
58832
  resource,
58807
- totalMatched: items.length,
58808
- offset,
58833
+ scanned,
58809
58834
  returned: page.length,
58810
58835
  hasNextPage
58811
58836
  });
58812
58837
  return {
58813
58838
  items: page,
58814
- pageInfo: { hasNextPage, hasPreviousPage: offset > 0 },
58839
+ pageInfo: { hasNextPage, hasPreviousPage: !!nextToken },
58815
58840
  ...nextTokenValue && { nextToken: nextTokenValue },
58816
58841
  consumedCapacity: costTracker.getAggregated()
58817
58842
  };
58818
58843
  }
58819
- var import_lib_dynamodb2, logger4;
58844
+ var import_lib_dynamodb2, logger4, SCAN_CHUNK_INITIAL, SCAN_CHUNK_MAX, SCAN_MAX_ITERATIONS;
58820
58845
  var init_idQuery = __esm({
58821
58846
  "src/server/operations/find/idQuery.ts"() {
58822
58847
  "use strict";
@@ -58834,6 +58859,9 @@ var init_idQuery = __esm({
58834
58859
  __name(executeSpecificIdQuery, "executeSpecificIdQuery");
58835
58860
  __name(executeInQuery, "executeInQuery");
58836
58861
  __name(executeAllRecordsQuery, "executeAllRecordsQuery");
58862
+ SCAN_CHUNK_INITIAL = 100;
58863
+ SCAN_CHUNK_MAX = 1e3;
58864
+ SCAN_MAX_ITERATIONS = 1e4;
58837
58865
  __name(executeAllRecordsQueryFullScan, "executeAllRecordsQueryFullScan");
58838
58866
  }
58839
58867
  });
@@ -59738,6 +59766,113 @@ var init_chunking = __esm({
59738
59766
  }
59739
59767
  });
59740
59768
 
59769
+ // src/server/utils/mergePatch.ts
59770
+ function isPlainObject(value) {
59771
+ return typeof value === "object" && value !== null && !Array.isArray(value);
59772
+ }
59773
+ function invalidPath(path, reason) {
59774
+ return new AppError("VALIDATION_ERROR" /* VALIDATION_ERROR */, `Invalid patch path "${path}": ${reason}`, 400, {
59775
+ path
59776
+ });
59777
+ }
59778
+ function mergeInto(target, patch) {
59779
+ for (const [key, value] of Object.entries(patch)) {
59780
+ if (key.includes(".")) {
59781
+ setByPath(target, key, value);
59782
+ } else {
59783
+ setKey(target, key, value, key);
59784
+ }
59785
+ }
59786
+ }
59787
+ function setKey(target, key, value, path) {
59788
+ if (key === "__proto__") {
59789
+ throw invalidPath(path, "forbidden segment");
59790
+ }
59791
+ if (value === null) {
59792
+ delete target[key];
59793
+ } else if (isPlainObject(value) && isPlainObject(target[key])) {
59794
+ mergeInto(target[key], value);
59795
+ } else {
59796
+ target[key] = value;
59797
+ }
59798
+ }
59799
+ function setByPath(target, path, value) {
59800
+ const keys = path.split(".");
59801
+ if (keys.some((k4) => k4 === "")) {
59802
+ throw invalidPath(path, "empty segment");
59803
+ }
59804
+ let current = target;
59805
+ for (let i4 = 0; i4 < keys.length; i4++) {
59806
+ const key = keys[i4];
59807
+ const isLast = i4 === keys.length - 1;
59808
+ if (Array.isArray(current)) {
59809
+ if (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= current.length) {
59810
+ throw invalidPath(path, `"${key}" is not a valid index (length ${current.length})`);
59811
+ }
59812
+ const index = Number(key);
59813
+ if (isLast) {
59814
+ if (value === null) {
59815
+ throw invalidPath(path, "array elements cannot be deleted by path");
59816
+ }
59817
+ const existing = current[index];
59818
+ if (isPlainObject(value) && isPlainObject(existing)) {
59819
+ mergeInto(existing, value);
59820
+ } else {
59821
+ current[index] = value;
59822
+ }
59823
+ return;
59824
+ }
59825
+ const next2 = current[index];
59826
+ if (isPlainObject(next2) || Array.isArray(next2)) {
59827
+ current = next2;
59828
+ } else {
59829
+ if (value === null) {
59830
+ return;
59831
+ }
59832
+ const created = {};
59833
+ current[index] = created;
59834
+ current = created;
59835
+ }
59836
+ continue;
59837
+ }
59838
+ if (isLast) {
59839
+ setKey(current, key, value, path);
59840
+ return;
59841
+ }
59842
+ if (key === "__proto__") {
59843
+ throw invalidPath(path, "forbidden segment");
59844
+ }
59845
+ const next = current[key];
59846
+ if (isPlainObject(next) || Array.isArray(next)) {
59847
+ current = next;
59848
+ } else {
59849
+ if (value === null) {
59850
+ return;
59851
+ }
59852
+ const created = {};
59853
+ current[key] = created;
59854
+ current = created;
59855
+ }
59856
+ }
59857
+ }
59858
+ function applyJsonMergePatch(target, patch) {
59859
+ const result = structuredClone(target);
59860
+ mergeInto(result, structuredClone(patch));
59861
+ return result;
59862
+ }
59863
+ var init_mergePatch = __esm({
59864
+ "src/server/utils/mergePatch.ts"() {
59865
+ "use strict";
59866
+ init_shared();
59867
+ __name(isPlainObject, "isPlainObject");
59868
+ __name(invalidPath, "invalidPath");
59869
+ __name(mergeInto, "mergeInto");
59870
+ __name(setKey, "setKey");
59871
+ __name(setByPath, "setByPath");
59872
+ __name(applyJsonMergePatch, "applyJsonMergePatch");
59873
+ }
59874
+ });
59875
+
59741
59876
  // src/server/utils/timestamps.ts
59742
59877
  var timestamps_exports = {};
59743
59878
  __export(timestamps_exports, {
@@ -59771,8 +59906,8 @@ function addUpdateTimestamp(data) {
59771
59906
  }
59772
59907
  const now = (/* @__PURE__ */ new Date()).toISOString();
59773
59908
  return {
59774
- [timestampFields.updatedAt]: now,
59775
- ...data
59909
+ ...data,
59910
+ [timestampFields.updatedAt]: data[timestampFields.updatedAt] ?? now
59776
59911
  };
59777
59912
  }
59778
59913
  var init_timestamps = __esm({
@@ -59790,46 +59925,6 @@ var updateMany_exports = {};
59790
59925
  __export(updateMany_exports, {
59791
59926
  handleUpdateMany: () => handleUpdateMany
59792
59927
  });
59793
- function expandDotNotation(patch) {
59794
- const result = {};
59795
- for (const [key, value] of Object.entries(patch)) {
59796
- if (key.includes(".")) {
59797
- const keys = key.split(".");
59798
- let current = result;
59799
- for (let i4 = 0; i4 < keys.length - 1; i4++) {
59800
- const k4 = keys[i4];
59801
- if (!(k4 in current)) {
59802
- current[k4] = {};
59803
- } else if (typeof current[k4] !== "object" || Array.isArray(current[k4])) {
59804
- current[k4] = {};
59805
- }
59806
- current = current[k4];
59807
- }
59808
- const lastKey = keys[keys.length - 1];
59809
- current[lastKey] = value;
59810
- } else {
59811
- result[key] = value;
59812
- }
59813
- }
59814
- return result;
59815
- }
59816
- function applyJsonMergePatch(target, patch) {
59817
- const expandedPatch = expandDotNotation(patch);
59818
- const result = { ...target };
59819
- for (const [key, value] of Object.entries(expandedPatch)) {
59820
- if (value === null) {
59821
- delete result[key];
59822
- } else if (typeof value === "object" && !Array.isArray(value) && value !== null && typeof result[key] === "object" && !Array.isArray(result[key]) && result[key] !== null) {
59823
- result[key] = applyJsonMergePatch(
59824
- result[key],
59825
- value
59826
- );
59827
- } else {
59828
- result[key] = value;
59829
- }
59830
- }
59831
- return result;
59832
- }
59833
59928
  async function handleUpdateMany(resource, params, requestId) {
59834
59929
  const { data: patchData, options } = params;
59835
59930
  const upsert = options?.upsert ?? false;
@@ -59957,11 +60052,9 @@ async function handleUpdateMany(resource, params, requestId) {
59957
60052
  const id = existingData.id;
59958
60053
  const oldShadowKeys = item.__shadowKeys ?? existingData.__shadowKeys ?? [];
59959
60054
  const actualPatchData2 = patchData.$set ? patchData.$set : patchData;
59960
- const mergedData = applyJsonMergePatch(removeShadowKeys(existingData), actualPatchData2);
59961
- const updatedData = addUpdateTimestamp({
59962
- ...mergedData,
59963
- id
59964
- });
60055
+ const timestampedPatch = addUpdateTimestamp(actualPatchData2);
60056
+ const mergedData = applyJsonMergePatch(removeShadowKeys(existingData), timestampedPatch);
60057
+ const updatedData = { ...mergedData, id };
59965
60058
  const newShadowRecords = generateShadowRecords(updatedData, resource, shadowConfig);
59966
60059
  const newShadowKeys = newShadowRecords.map((shadow) => shadow.SK);
59967
60060
  const mainSK = generateMainRecordSK2(id);
@@ -60242,10 +60335,9 @@ var init_updateMany = __esm({
60242
60335
  init_chunking();
60243
60336
  init_cost_tracker();
60244
60337
  init_dynamodb3();
60338
+ init_mergePatch();
60245
60339
  init_timestamps();
60246
60340
  logger11 = createLogger({ service: "records-lambda" });
60247
- __name(expandDotNotation, "expandDotNotation");
60248
- __name(applyJsonMergePatch, "applyJsonMergePatch");
60249
60341
  __name(handleUpdateMany, "handleUpdateMany");
60250
60342
  __name(getPreparationErrorCode, "getPreparationErrorCode");
60251
60343
  }
@@ -60361,6 +60453,9 @@ async function handleUpdateOne(resource, params, requestId) {
60361
60453
  if (updateManyResult.count === 0) {
60362
60454
  const error2 = Object.values(updateManyResult.errors || {})[0];
60363
60455
  if (error2) {
60456
+ if (error2.code === "VALIDATION_ERROR" /* VALIDATION_ERROR */) {
60457
+ throw new AppError("VALIDATION_ERROR" /* VALIDATION_ERROR */, error2.message ?? "Invalid patch", 400);
60458
+ }
60364
60459
  throw new Error(`Failed to update record: ${error2.message}`);
60365
60460
  } else {
60366
60461
  throw new Error(`Failed to update record: ${targetId}`);
@@ -60400,6 +60495,9 @@ async function handleUpdateOne(resource, params, requestId) {
60400
60495
  if (updateManyResult.count === 0) {
60401
60496
  const error2 = Object.values(updateManyResult.errors || {})[0];
60402
60497
  if (error2) {
60498
+ if (error2.code === "VALIDATION_ERROR" /* VALIDATION_ERROR */) {
60499
+ throw new AppError("VALIDATION_ERROR" /* VALIDATION_ERROR */, error2.message ?? "Invalid patch", 400);
60500
+ }
60403
60501
  throw new Error(`Failed to update record: ${error2.message}`);
60404
60502
  } else {
60405
60503
  throw new Error(`No records found matching filter`);