electrodb 2.10.6 → 2.11.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.
package/index.d.ts CHANGED
@@ -3655,6 +3655,7 @@ export interface Schema<A extends string, F extends string, C extends string> {
3655
3655
  [accessPattern: string]: {
3656
3656
  readonly project?: "keys_only";
3657
3657
  readonly index?: string;
3658
+ readonly scope?: string;
3658
3659
  readonly type?: "clustered" | "isolated";
3659
3660
  readonly collection?: AccessPatternCollection<C>;
3660
3661
  readonly pk: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrodb",
3
- "version": "2.10.6",
3
+ "version": "2.11.0",
4
4
  "description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/client.js CHANGED
@@ -1,5 +1,5 @@
1
- const lib = require("@aws-sdk/lib-dynamodb");
2
- const util = require("@aws-sdk/lib-dynamodb/dist-cjs/commands/utils");
1
+ const lib = require('@aws-sdk/lib-dynamodb')
2
+ const util = require('@aws-sdk/lib-dynamodb/dist-cjs/commands/utils')
3
3
  const { isFunction } = require("./validations");
4
4
  const { ElectroError, ErrorCodes } = require("./errors");
5
5
  const DocumentClientVersions = {
package/src/entity.js CHANGED
@@ -494,7 +494,7 @@ class Entity {
494
494
  async go(method, parameters = {}, config = {}) {
495
495
  let stackTrace;
496
496
  if (!config.originalErr) {
497
- stackTrace = new e.ElectroError(e.ErrorCodes.AWSError).stack;
497
+ stackTrace = new e.ElectroError(e.ErrorCodes.AWSError);
498
498
  }
499
499
  try {
500
500
  switch (method) {
@@ -513,13 +513,9 @@ class Entity {
513
513
  return Promise.reject(err);
514
514
  } else {
515
515
  if (err.__isAWSError) {
516
- const error = new e.ElectroError(
517
- e.ErrorCodes.AWSError,
518
- `Error thrown by DynamoDB client: "${err.message}"`,
519
- err,
520
- );
521
- error.stack = stackTrace;
522
- return Promise.reject(error);
516
+ stackTrace.message = `Error thrown by DynamoDB client: "${err.message}" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error`;
517
+ stackTrace.cause = err;
518
+ return Promise.reject(stackTrace);
523
519
  } else if (err.isElectroError) {
524
520
  return Promise.reject(err);
525
521
  } else {
@@ -926,7 +922,7 @@ class Entity {
926
922
  formatResponse(response, index, config = {}) {
927
923
  let stackTrace;
928
924
  if (!config.originalErr) {
929
- stackTrace = new e.ElectroError(e.ErrorCodes.AWSError).stack;
925
+ stackTrace = new e.ElectroError(e.ErrorCodes.AWSError);
930
926
  }
931
927
  try {
932
928
  let results = {};
@@ -1021,14 +1017,9 @@ class Entity {
1021
1017
  ) {
1022
1018
  throw err;
1023
1019
  } else {
1024
- const error = new e.ElectroError(
1025
- e.ErrorCodes.AWSError,
1026
- err.message,
1027
- err,
1028
- );
1029
- error.stack = stackTrace;
1030
-
1031
- throw error;
1020
+ stackTrace.message = `Error thrown by DynamoDB client: "${err.message}" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error`;
1021
+ stackTrace.cause = err;
1022
+ throw stackTrace;
1032
1023
  }
1033
1024
  }
1034
1025
  }
@@ -3231,6 +3222,9 @@ class Entity {
3231
3222
 
3232
3223
  // If keys are not custom, set the prefixes
3233
3224
  if (!keys.pk.isCustom) {
3225
+ if (tableIndex.scope) {
3226
+ pk = `${pk}_${tableIndex.scope}`;
3227
+ }
3234
3228
  keys.pk.prefix = u.formatKeyCasing(pk, tableIndex.pk.casing);
3235
3229
  }
3236
3230
 
@@ -3851,6 +3845,7 @@ class Entity {
3851
3845
  let indexName = index.index || TableIndex;
3852
3846
  let indexType =
3853
3847
  typeof index.type === "string" ? index.type : IndexTypes.isolated;
3848
+ let indexScope = index.scope || "";
3854
3849
  if (indexType === "clustered") {
3855
3850
  clusteredIndexes.add(accessPattern);
3856
3851
  }
@@ -3949,14 +3944,15 @@ class Entity {
3949
3944
  }
3950
3945
  }
3951
3946
 
3952
- let definition = {
3947
+ let definition= {
3953
3948
  pk,
3954
3949
  sk,
3955
- collection,
3956
3950
  hasSk,
3951
+ collection,
3957
3952
  customFacets,
3958
- index: indexName,
3959
3953
  type: indexType,
3954
+ index: indexName,
3955
+ scope: indexScope,
3960
3956
  };
3961
3957
 
3962
3958
  indexHasSubCollections[indexName] =
package/src/service.js CHANGED
@@ -584,6 +584,7 @@ class Service {
584
584
  let pkFieldMatch = definition.pk.field === providedIndex.pk.field;
585
585
  let pkFacetLengthMatch =
586
586
  definition.pk.facets.length === providedIndex.pk.facets.length;
587
+ let scopeMatch = definition.scope === providedIndex.scope;
587
588
  let mismatchedFacetLabels = [];
588
589
  let collectionDifferences = [];
589
590
  let definitionIndexName = u.formatIndexNameForDisplay(definition.index);
@@ -631,6 +632,16 @@ class Service {
631
632
  }
632
633
  }
633
634
 
635
+ if (!scopeMatch) {
636
+ collectionDifferences.push(
637
+ `The index scope value provided "${
638
+ providedIndex.scope || "undefined"
639
+ }" does not match established index scope value "${
640
+ definition.scope || "undefined"
641
+ }" on index "${providedIndexName}". Index scope options must match across all entities participating in a collection`,
642
+ );
643
+ }
644
+
634
645
  if (!isCustomMatchPK) {
635
646
  collectionDifferences.push(
636
647
  `The usage of key templates the partition key on index ${definitionIndexName} must be consistent across all Entities, some entities provided use template while others do not`,
@@ -119,6 +119,10 @@ const Index = {
119
119
  enum: ["string", "number"],
120
120
  required: false,
121
121
  },
122
+ scope: {
123
+ type: "string",
124
+ required: false,
125
+ }
122
126
  },
123
127
  },
124
128
  sk: {