electrodb 3.6.2 → 3.7.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/src/errors.js CHANGED
@@ -133,28 +133,28 @@ const ErrorCodes = {
133
133
  name: "IncompatibleKeyCasing",
134
134
  sym: ErrorCode,
135
135
  },
136
- InvalidClientProvided: {
136
+ InvalidListenerProvided: {
137
137
  code: 1021,
138
- section: "invalid-client-provided",
139
- name: "InvalidClientProvided",
138
+ section: "invalid-listener-provided",
139
+ name: "InvalidListenerProvided",
140
140
  sym: ErrorCode,
141
141
  },
142
- InconsistentIndexDefinition: {
142
+ InvalidLoggerProvided: {
143
143
  code: 1022,
144
- section: "inconsistent-index-definition",
145
- name: "Inconsistent Index Definition",
144
+ section: "invalid-logger-provided",
145
+ name: "InvalidLoggerProvided",
146
146
  sym: ErrorCode,
147
147
  },
148
- InvalidListenerProvided: {
148
+ InvalidClientProvided: {
149
149
  code: 1023,
150
- section: "invalid-listener-provided",
151
- name: "InvalidListenerProvided",
150
+ section: "invalid-client-provided",
151
+ name: "InvalidClientProvided",
152
152
  sym: ErrorCode,
153
153
  },
154
- InvalidLoggerProvided: {
154
+ InconsistentIndexDefinition: {
155
155
  code: 1024,
156
- section: "invalid-listener-provided",
157
- name: "InvalidListenerProvided",
156
+ section: "inconsistent-index-definition",
157
+ name: "Inconsistent Index Definition",
158
158
  sym: ErrorCode,
159
159
  },
160
160
  InvalidProjectionDefinition: {
@@ -163,6 +163,12 @@ const ErrorCodes = {
163
163
  name: "InvalidProjectionDefinition",
164
164
  sym: ErrorCode,
165
165
  },
166
+ InvalidIndexDefinition: {
167
+ code: 1026,
168
+ section: "invalid-index-definition",
169
+ name: "InvalidIndexDefinition",
170
+ sym: ErrorCode,
171
+ },
166
172
  MissingAttribute: {
167
173
  code: 2001,
168
174
  section: "missing-attribute",
@@ -235,6 +241,12 @@ const ErrorCodes = {
235
241
  name: "IncompleteIndexCompositesAttributesProvided",
236
242
  sym: ErrorCode,
237
243
  },
244
+ InvalidQueryParameters: {
245
+ code: 2013,
246
+ section: "invalid-query-parameters",
247
+ name: "InvalidQueryParameters",
248
+ sym: ErrorCode,
249
+ },
238
250
  InvalidAttribute: {
239
251
  code: 3001,
240
252
  section: "invalid-attribute",
package/src/operations.js CHANGED
@@ -90,9 +90,9 @@ class ExpressionState {
90
90
  }
91
91
 
92
92
  setValue(name, value) {
93
- name = this.formatName(name);
94
- let valueCount = this.incrementName(name);
95
- let expression = `:${name}${valueCount}`;
93
+ const formated = this.formatName(name);
94
+ let valueCount = this.incrementName(formated);
95
+ let expression = `:${formated}${valueCount}`;
96
96
  this.values[expression] = value;
97
97
  return expression;
98
98
  }
package/src/service.js CHANGED
@@ -16,7 +16,7 @@ const {
16
16
  DataOptions, IndexProjectionOptions,
17
17
  } = require("./types");
18
18
  const { FilterFactory } = require("./filters");
19
- const { FilterOperations } = require("./operations");
19
+ const { FilterOperations, ExpressionState } = require("./operations");
20
20
  const { WhereFactory } = require("./where");
21
21
  const v = require("./validations");
22
22
  const c = require("./client");
@@ -279,9 +279,11 @@ class Service {
279
279
 
280
280
  this.entities[name] = entity;
281
281
  for (let collection of this.entities[name].model.collections) {
282
- // todo: this used to be inside the collection callback, it does not do well being ran multiple times
283
- // this forlook adds the entity filters multiple times
284
- this._addCollectionEntity(collection, name, this.entities[name]);
282
+ this._addCollectionEntity(
283
+ collection,
284
+ name,
285
+ this.entities[name],
286
+ );
285
287
  this.collections[collection] = (...facets) => {
286
288
  return this._makeCollectionChain(
287
289
  {
@@ -659,7 +661,10 @@ class Service {
659
661
  );
660
662
  }
661
663
 
662
- if (definition.type === "clustered") {
664
+ if (
665
+ definition.type === IndexTypes.clustered ||
666
+ definition.type === IndexTypes.composite
667
+ ) {
663
668
  for (
664
669
  let i = 0;
665
670
  i <
@@ -933,11 +938,12 @@ class Service {
933
938
 
934
939
  if (
935
940
  providedSubCollections.length > 1 &&
936
- providedType === IndexTypes.clustered
941
+ (providedType === IndexTypes.clustered ||
942
+ providedType === IndexTypes.composite)
937
943
  ) {
938
944
  throw new e.ElectroError(
939
945
  e.ErrorCodes.InvalidJoin,
940
- `Clustered indexes do not support sub-collections. The sub-collection "${collectionName}", on Entity "${entityName}" must be defined as either an individual collection name or the index must be redefined as an isolated cluster`,
946
+ `"${providedType}" indexes do not support sub-collections. The sub-collection "${collectionName}", on Entity "${entityName}" must be defined as either an individual collection name or the index must be redefined as an "${IndexTypes.isolated}" index`,
941
947
  );
942
948
  }
943
949
  const existingRequiredIndex =
@@ -997,7 +1003,11 @@ class Service {
997
1003
  }
998
1004
  }
999
1005
 
1000
- _addCollectionEntity(collection = "", name = "", entity = {}) {
1006
+ _addCollectionEntity(
1007
+ collection = "",
1008
+ name = "",
1009
+ entity = {},
1010
+ ) {
1001
1011
  let providedIndex = this._getEntityIndexFromCollectionName(
1002
1012
  collection,
1003
1013
  entity,
@@ -1007,11 +1017,7 @@ class Service {
1007
1017
  entities: {},
1008
1018
  keys: {},
1009
1019
  attributes: {},
1010
- identifiers: {
1011
- names: {},
1012
- values: {},
1013
- expression: "",
1014
- },
1020
+ identifiers: new ExpressionState({ prefix: "_c" }),
1015
1021
  index: undefined,
1016
1022
  table: "",
1017
1023
  collection: [],
@@ -1060,10 +1066,12 @@ class Service {
1060
1066
  this.collectionSchema[collection].keys,
1061
1067
  );
1062
1068
  this.collectionSchema[collection].entities[name] = entity;
1069
+
1063
1070
  this.collectionSchema[collection].identifiers =
1064
1071
  this._processEntityIdentifiers(
1065
1072
  this.collectionSchema[collection].identifiers,
1066
- entity.getIdentifierExpressions(name),
1073
+ name,
1074
+ entity,
1067
1075
  );
1068
1076
  this.collectionSchema[collection].index =
1069
1077
  this._processEntityCollectionIndex(
@@ -1104,20 +1112,16 @@ class Service {
1104
1112
  }
1105
1113
  }
1106
1114
 
1107
- _processEntityIdentifiers(existing = {}, { names, values, expression } = {}) {
1108
- let identifiers = {};
1109
- if (names) {
1110
- identifiers.names = Object.assign({}, existing.names, names);
1111
- }
1112
- if (values) {
1113
- identifiers.values = Object.assign({}, existing.values, values);
1114
- }
1115
+ _processEntityIdentifiers(state, alias, entity) {
1116
+ const expression = entity.applyIdentifierExpressionState(state, alias);
1115
1117
  if (expression) {
1116
- identifiers.expression = [existing.expression, expression]
1118
+ const combined = [state.getExpression().trim(), expression.trim()]
1117
1119
  .filter(Boolean)
1118
1120
  .join(" OR ");
1121
+ state.setExpression(combined);
1119
1122
  }
1120
- return identifiers;
1123
+
1124
+ return state;
1121
1125
  }
1122
1126
  }
1123
1127
 
package/src/types.js CHANGED
@@ -31,6 +31,7 @@ const QueryTypes = {
31
31
  between: "between",
32
32
  collection: "collection",
33
33
  clustered_collection: "clustered_collection",
34
+ composite_collection: "composite_collection",
34
35
  is: "is",
35
36
  };
36
37
 
@@ -89,6 +90,7 @@ const MethodTypeTranslation = {
89
90
  const IndexTypes = {
90
91
  isolated: "isolated",
91
92
  clustered: "clustered",
93
+ composite: "composite",
92
94
  };
93
95
 
94
96
  const Comparisons = {
@@ -229,6 +231,7 @@ const ItemOperations = {
229
231
  subtract: "subtract",
230
232
  append: "append",
231
233
  ifNotExists: "ifNotExists",
234
+ none: "",
232
235
  };
233
236
 
234
237
  const UpsertOperations = {
@@ -1,5 +1,5 @@
1
1
  const e = require("./errors");
2
- const { KeyCasing, IndexProjectionOptions } = require("./types");
2
+ const { KeyCasing, IndexProjectionOptions, IndexTypes } = require("./types");
3
3
 
4
4
  const Validator = require("jsonschema").Validator;
5
5
  Validator.prototype.customFormats.isFunction = function (input) {
@@ -89,7 +89,7 @@ const Index = {
89
89
  properties: {
90
90
  field: {
91
91
  type: "string",
92
- required: true,
92
+ required: false,
93
93
  },
94
94
  facets: {
95
95
  type: ["array", "string"],
@@ -127,11 +127,10 @@ const Index = {
127
127
  },
128
128
  sk: {
129
129
  type: "object",
130
- required: ["field"],
131
130
  properties: {
132
131
  field: {
133
132
  type: "string",
134
- required: true,
133
+ required: false,
135
134
  },
136
135
  facets: {
137
136
  type: ["array", "string"],
@@ -171,7 +170,7 @@ const Index = {
171
170
  },
172
171
  type: {
173
172
  type: "string",
174
- enum: ["clustered", "isolated"],
173
+ enum: Object.values(IndexTypes),
175
174
  required: false,
176
175
  },
177
176
  condition: {
@@ -190,7 +189,6 @@ const Index = {
190
189
 
191
190
  const Modelv1 = {
192
191
  type: "object",
193
- required: true,
194
192
  properties: {
195
193
  model: {
196
194
  type: "object",
@@ -233,7 +231,6 @@ const Modelv1 = {
233
231
 
234
232
  const ModelBeta = {
235
233
  type: "object",
236
- required: true,
237
234
  properties: {
238
235
  service: {
239
236
  type: "string",