electrodb 2.2.4 → 2.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrodb",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
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
@@ -54,7 +54,7 @@ class Entity {
54
54
  this._whereBuilder = new WhereFactory(this.model.schema.attributes, FilterOperations);
55
55
  this._clausesWithFilters = this._filterBuilder.injectFilterClauses(clauses, this.model.filters);
56
56
  this._clausesWithFilters = this._whereBuilder.injectWhereClauses(this._clausesWithFilters);
57
- this.scan = this._makeChain(TableIndex, this._clausesWithFilters, clauses.index, {_isPagination: true}).scan();
57
+
58
58
  this.query = {};
59
59
  for (let accessPattern in this.model.indexes) {
60
60
  let index = this.model.indexes[accessPattern].index;
@@ -75,6 +75,10 @@ class Entity {
75
75
  this.schema = model;
76
76
  }
77
77
 
78
+ get scan() {
79
+ return this._makeChain(TableIndex, this._clausesWithFilters, clauses.index, {_isPagination: true}).scan();
80
+ }
81
+
78
82
  setIdentifier(type = "", identifier = "") {
79
83
  if (!this.identifiers[type]) {
80
84
  throw new e.ElectroError(e.ErrorCodes.InvalidIdentifier, `Invalid identifier type: "${type}". Valid identifiers include: ${u.commaSeparatedString(Object.keys(this.identifiers))}`);
package/src/operations.js CHANGED
@@ -431,24 +431,32 @@ class AttributeOperationProxy {
431
431
  return ops;
432
432
  }
433
433
 
434
- static pathProxy(paths, root, target, builder) {
435
- return new Proxy(() => ({paths, root, target}), {
436
- get: (_, prop) => {
434
+ static pathProxy(build) {
435
+ return new Proxy(() => build(), {
436
+ get: (_, prop, o) => {
437
437
  if (prop === "__is_clause__") {
438
- return AttributeProxySymbol
438
+ return AttributeProxySymbol;
439
439
  } else {
440
- const attribute = target.getChild(prop);
441
- let field;
442
- if (attribute === undefined) {
443
- throw new Error(`Invalid attribute "${prop}" at path "${paths.json}".`);
444
- } else if (attribute === root && attribute.type === AttributeTypes.any) {
445
- // This function is only called if a nested property is called. If this attribute is ultimately the root, don't use the root's field name
446
- field = prop;
447
- } else {
448
- field = attribute.field;
449
- }
450
- paths = builder.setName(paths, prop, field);
451
- return AttributeOperationProxy.pathProxy(paths, root, attribute, builder);
440
+ return AttributeOperationProxy.pathProxy(() => {
441
+ const { paths, root, target, builder } = build();
442
+ const attribute = target.getChild(prop);
443
+ let field;
444
+ if (attribute === undefined) {
445
+ throw new Error(`Invalid attribute "${prop}" at path "${paths.json}".`);
446
+ } else if (attribute === root && attribute.type === AttributeTypes.any) {
447
+ // This function is only called if a nested property is called. If this attribute is ultimately the root, don't use the root's field name
448
+ field = prop;
449
+ } else {
450
+ field = attribute.field;
451
+ }
452
+
453
+ return {
454
+ root,
455
+ builder,
456
+ target: attribute,
457
+ paths: builder.setName(paths, prop, field),
458
+ }
459
+ });
452
460
  }
453
461
  }
454
462
  });
@@ -459,8 +467,15 @@ class AttributeOperationProxy {
459
467
  for (let [name, attribute] of Object.entries(attributes)) {
460
468
  Object.defineProperty(attr, name, {
461
469
  get: () => {
462
- const paths = builder.setName({}, attribute.name, attribute.field);
463
- return AttributeOperationProxy.pathProxy(paths, attribute, attribute, builder);
470
+ return AttributeOperationProxy.pathProxy(() => {
471
+ const paths = builder.setName({}, attribute.name, attribute.field);
472
+ return {
473
+ paths,
474
+ root: attribute,
475
+ target: attribute,
476
+ builder,
477
+ }
478
+ });
464
479
  }
465
480
  });
466
481
  }