@awsless/dynamodb-server 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +16 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -41,7 +41,7 @@ function createJavaServer(port, region) {
41
41
  const ping = async () => {
42
42
  const client = getClient();
43
43
  try {
44
- const response = await client.send(new ListTablesCommand({}));
44
+ const response = await client.send(new ListTablesCommand({}), { requestTimeout: 250 });
45
45
  return Array.isArray(response.TableNames);
46
46
  } catch {
47
47
  return false;
@@ -838,7 +838,6 @@ function compareValues(a, b) {
838
838
  }
839
839
 
840
840
  // src/store/item.ts
841
- import { createHash } from "crypto";
842
841
  function extractKey(item, keySchema) {
843
842
  const key = {};
844
843
  for (const element of keySchema) {
@@ -889,16 +888,6 @@ function deepClone(obj) {
889
888
  function estimateItemSize(item) {
890
889
  return JSON.stringify(item).length;
891
890
  }
892
- function extractRawValue(value) {
893
- if ("S" in value) return value.S;
894
- if ("N" in value) return value.N;
895
- if ("B" in value) return value.B;
896
- return serializeAttributeValue(value);
897
- }
898
- function hashAttributeValue(value) {
899
- const raw = extractRawValue(value);
900
- return createHash("md5").update("Outliers" + raw).digest("hex");
901
- }
902
891
 
903
892
  // src/expressions/key-condition.ts
904
893
  function parseKeyCondition(expression, keySchema, context) {
@@ -1277,6 +1266,20 @@ function resolveOperand(item, operand, context) {
1277
1266
  if (operand.startsWith(":")) {
1278
1267
  return context.expressionAttributeValues?.[operand];
1279
1268
  }
1269
+ const ifNotExistsMatch = operand.match(/^if_not_exists\s*\(\s*([^,]+)\s*,\s*(.+)\s*\)$/i);
1270
+ if (ifNotExistsMatch) {
1271
+ const existing = resolveOperand(item, ifNotExistsMatch[1].trim(), context);
1272
+ return existing !== void 0 ? existing : resolveOperand(item, ifNotExistsMatch[2].trim(), context);
1273
+ }
1274
+ const listAppendMatch = operand.match(/^list_append\s*\(\s*([^,]+)\s*,\s*(.+)\s*\)$/i);
1275
+ if (listAppendMatch) {
1276
+ const list1 = resolveOperand(item, listAppendMatch[1].trim(), context);
1277
+ const list2 = resolveOperand(item, listAppendMatch[2].trim(), context);
1278
+ if (list1 && "L" in list1 && list2 && "L" in list2) {
1279
+ return { L: [...list1.L, ...list2.L] };
1280
+ }
1281
+ return list1 && "L" in list1 ? list1 : list2;
1282
+ }
1280
1283
  const segments = parsePath(operand, context.expressionAttributeNames);
1281
1284
  return getValueAtPath(item, segments);
1282
1285
  }
@@ -2579,7 +2582,7 @@ var Table = class {
2579
2582
  const hashA = a[hashAttr];
2580
2583
  const hashB = b[hashAttr];
2581
2584
  if (hashA && hashB) {
2582
- const hashCmp = hashAttributeValue(hashA).localeCompare(hashAttributeValue(hashB));
2585
+ const hashCmp = this.compareAttributes(hashA, hashB);
2583
2586
  if (hashCmp !== 0) return hashCmp;
2584
2587
  }
2585
2588
  if (rangeAttr) {
@@ -2735,29 +2738,12 @@ var Table = class {
2735
2738
  throw new Error(`Index ${indexName} not found`);
2736
2739
  }
2737
2740
  const indexHashAttr = getHashKey(indexData.keySchema);
2738
- const indexRangeAttr = getRangeKey(indexData.keySchema);
2739
2741
  const matchingItems = [];
2740
2742
  for (const item of this.items.values()) {
2741
2743
  if (item[indexHashAttr]) {
2742
2744
  matchingItems.push(deepClone(item));
2743
2745
  }
2744
2746
  }
2745
- matchingItems.sort((a, b) => {
2746
- const hashA = a[indexHashAttr];
2747
- const hashB = b[indexHashAttr];
2748
- if (hashA && hashB) {
2749
- const hashCmp = hashAttributeValue(hashA).localeCompare(hashAttributeValue(hashB));
2750
- if (hashCmp !== 0) return hashCmp;
2751
- }
2752
- if (indexRangeAttr) {
2753
- const rangeA = a[indexRangeAttr];
2754
- const rangeB = b[indexRangeAttr];
2755
- if (rangeA && rangeB) {
2756
- return this.compareAttributes(rangeA, rangeB);
2757
- }
2758
- }
2759
- return 0;
2760
- });
2761
2747
  let startIdx = 0;
2762
2748
  if (exclusiveStartKey) {
2763
2749
  const startKey = serializeKey(exclusiveStartKey, this.keySchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/dynamodb-server",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",