electrodb 2.10.7 → 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.7",
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/entity.js CHANGED
@@ -3222,6 +3222,9 @@ class Entity {
3222
3222
 
3223
3223
  // If keys are not custom, set the prefixes
3224
3224
  if (!keys.pk.isCustom) {
3225
+ if (tableIndex.scope) {
3226
+ pk = `${pk}_${tableIndex.scope}`;
3227
+ }
3225
3228
  keys.pk.prefix = u.formatKeyCasing(pk, tableIndex.pk.casing);
3226
3229
  }
3227
3230
 
@@ -3842,6 +3845,7 @@ class Entity {
3842
3845
  let indexName = index.index || TableIndex;
3843
3846
  let indexType =
3844
3847
  typeof index.type === "string" ? index.type : IndexTypes.isolated;
3848
+ let indexScope = index.scope || "";
3845
3849
  if (indexType === "clustered") {
3846
3850
  clusteredIndexes.add(accessPattern);
3847
3851
  }
@@ -3940,14 +3944,15 @@ class Entity {
3940
3944
  }
3941
3945
  }
3942
3946
 
3943
- let definition = {
3947
+ let definition= {
3944
3948
  pk,
3945
3949
  sk,
3946
- collection,
3947
3950
  hasSk,
3951
+ collection,
3948
3952
  customFacets,
3949
- index: indexName,
3950
3953
  type: indexType,
3954
+ index: indexName,
3955
+ scope: indexScope,
3951
3956
  };
3952
3957
 
3953
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: {