electrodb 2.8.0 → 2.8.1
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 +1 -1
- package/src/entity.js +4 -2
- package/src/schema.js +15 -14
package/package.json
CHANGED
package/src/entity.js
CHANGED
|
@@ -3595,7 +3595,6 @@ class Entity {
|
|
|
3595
3595
|
|
|
3596
3596
|
_parseModel(model, config = {}) {
|
|
3597
3597
|
/** start beta/v1 condition **/
|
|
3598
|
-
const {client} = config;
|
|
3599
3598
|
let modelVersion = u.getModelVersion(model);
|
|
3600
3599
|
let service, entity, version, table, name;
|
|
3601
3600
|
switch(modelVersion) {
|
|
@@ -3635,7 +3634,10 @@ class Entity {
|
|
|
3635
3634
|
indexAccessPattern,
|
|
3636
3635
|
indexHasSubCollections,
|
|
3637
3636
|
} = this._normalizeIndexes(model.indexes);
|
|
3638
|
-
let schema = new Schema(model.attributes, facets, {
|
|
3637
|
+
let schema = new Schema(model.attributes, facets, {
|
|
3638
|
+
getClient: () => this.client,
|
|
3639
|
+
isRoot: true,
|
|
3640
|
+
});
|
|
3639
3641
|
let filters = this._normalizeFilters(model.filters);
|
|
3640
3642
|
// todo: consider a rename
|
|
3641
3643
|
let prefixes = this._normalizeKeyFixings({service, entity, version, indexes, modelVersion, clusteredIndexes, schema});
|
package/src/schema.js
CHANGED
|
@@ -127,7 +127,7 @@ class Attribute {
|
|
|
127
127
|
this.parent = { parentType: this.type, parentPath: this.path };
|
|
128
128
|
this.get = this._makeGet(definition.get);
|
|
129
129
|
this.set = this._makeSet(definition.set);
|
|
130
|
-
this.
|
|
130
|
+
this.getClient = definition.getClient;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
static buildChildAttributes(type, definition, parent) {
|
|
@@ -145,25 +145,25 @@ class Attribute {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
static buildChildListItems(definition, parent) {
|
|
148
|
-
const {items,
|
|
148
|
+
const {items, getClient} = definition;
|
|
149
149
|
const prop = {...items, ...parent};
|
|
150
150
|
// The use of "*" is to ensure the child's name is "*" when added to the traverser and searching for the children of a list
|
|
151
|
-
return Schema.normalizeAttributes({ '*': prop }, {}, {
|
|
151
|
+
return Schema.normalizeAttributes({ '*': prop }, {}, {getClient, traverser: parent.traverser, parent}).attributes["*"];
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
static buildChildSetItems(definition, parent) {
|
|
155
|
-
const {items,
|
|
155
|
+
const {items, getClient} = definition;
|
|
156
156
|
|
|
157
157
|
const allowedTypes = [AttributeTypes.string, AttributeTypes.boolean, AttributeTypes.number, AttributeTypes.enum];
|
|
158
158
|
if (!Array.isArray(items) && !allowedTypes.includes(items)) {
|
|
159
159
|
throw new e.ElectroError(e.ErrorCodes.InvalidAttributeDefinition, `Invalid "items" definition for Set attribute: "${definition.path}". Acceptable item types include ${u.commaSeparatedString(allowedTypes)}`);
|
|
160
160
|
}
|
|
161
161
|
const prop = {type: items, ...parent};
|
|
162
|
-
return Schema.normalizeAttributes({ prop }, {}, {
|
|
162
|
+
return Schema.normalizeAttributes({ prop }, {}, {getClient, traverser: parent.traverser, parent}).attributes.prop;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
static buildChildMapProperties(definition, parent) {
|
|
166
|
-
const {properties,
|
|
166
|
+
const {properties, getClient} = definition;
|
|
167
167
|
if (!properties || typeof properties !== "object") {
|
|
168
168
|
throw new e.ElectroError(e.ErrorCodes.InvalidAttributeDefinition, `Invalid "properties" definition for Map attribute: "${definition.path}". The "properties" definition must describe the attributes that the Map will accept`);
|
|
169
169
|
}
|
|
@@ -171,7 +171,7 @@ class Attribute {
|
|
|
171
171
|
for (let name of Object.keys(properties)) {
|
|
172
172
|
attributes[name] = {...properties[name], ...parent};
|
|
173
173
|
}
|
|
174
|
-
return Schema.normalizeAttributes(attributes, {}, {
|
|
174
|
+
return Schema.normalizeAttributes(attributes, {}, {getClient, traverser: parent.traverser, parent});
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
static buildPath(name, type, parentPath) {
|
|
@@ -886,11 +886,12 @@ class SetAttribute extends Attribute {
|
|
|
886
886
|
}
|
|
887
887
|
|
|
888
888
|
_createDDBSet(value) {
|
|
889
|
-
|
|
889
|
+
const client = this.getClient();
|
|
890
|
+
if (client && typeof client.createSet === "function") {
|
|
890
891
|
value = Array.isArray(value)
|
|
891
892
|
? Array.from(new Set(value))
|
|
892
893
|
: value;
|
|
893
|
-
return
|
|
894
|
+
return client.createSet(value, { validate: true });
|
|
894
895
|
} else {
|
|
895
896
|
return new DynamoDBSet(value, this.items.type);
|
|
896
897
|
}
|
|
@@ -1005,10 +1006,10 @@ class SetAttribute extends Attribute {
|
|
|
1005
1006
|
}
|
|
1006
1007
|
|
|
1007
1008
|
class Schema {
|
|
1008
|
-
constructor(properties = {}, facets = {}, {traverser = new AttributeTraverser(),
|
|
1009
|
+
constructor(properties = {}, facets = {}, {traverser = new AttributeTraverser(), getClient, parent, isRoot} = {}) {
|
|
1009
1010
|
this._validateProperties(properties, parent);
|
|
1010
|
-
let schema = Schema.normalizeAttributes(properties, facets, {traverser,
|
|
1011
|
-
this.
|
|
1011
|
+
let schema = Schema.normalizeAttributes(properties, facets, {traverser, getClient, parent, isRoot});
|
|
1012
|
+
this.getClient = getClient;
|
|
1012
1013
|
this.attributes = schema.attributes;
|
|
1013
1014
|
this.enums = schema.enums;
|
|
1014
1015
|
this.translationForTable = schema.translationForTable;
|
|
@@ -1021,7 +1022,7 @@ class Schema {
|
|
|
1021
1022
|
this.isRoot = !!isRoot;
|
|
1022
1023
|
}
|
|
1023
1024
|
|
|
1024
|
-
static normalizeAttributes(attributes = {}, facets = {}, {traverser,
|
|
1025
|
+
static normalizeAttributes(attributes = {}, facets = {}, {traverser, getClient, parent, isRoot} = {}) {
|
|
1025
1026
|
const attributeHasParent = !!parent;
|
|
1026
1027
|
let invalidProperties = [];
|
|
1027
1028
|
let normalized = {};
|
|
@@ -1114,7 +1115,7 @@ class Schema {
|
|
|
1114
1115
|
let definition = {
|
|
1115
1116
|
name,
|
|
1116
1117
|
field,
|
|
1117
|
-
|
|
1118
|
+
getClient,
|
|
1118
1119
|
casing,
|
|
1119
1120
|
prefix,
|
|
1120
1121
|
postfix,
|