electrodb 1.8.0 → 1.8.3
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/CHANGELOG.md +13 -1
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/entity.js +12 -0
- package/src/schema.js +1 -1
- package/src/service.js +8 -0
- package/src/validations.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -166,4 +166,16 @@ All notable changes to this project will be documented in this file. Breaking ch
|
|
|
166
166
|
- Expected typings for the injected v2 client now include methods for `transactWrite` and `transactGet`
|
|
167
167
|
### Changed
|
|
168
168
|
- Map attributes will now always resolve to least an empty object on a `create` and `put` methods (instead of just the root map)
|
|
169
|
-
- In the past, default values for property attributes on maps only resolves when a user provided an object to place the values on. Now default values within maps attributes will now always resolve onto the object on `create` and `put` methods.
|
|
169
|
+
- In the past, default values for property attributes on maps only resolves when a user provided an object to place the values on. Now default values within maps attributes will now always resolve onto the object on `create` and `put` methods.
|
|
170
|
+
|
|
171
|
+
## [1.8.1] - 2022-03-29
|
|
172
|
+
### Fixed
|
|
173
|
+
- Solidifying default application methodology: default values for nested properties will be applied up until an undefined default occurs or default callback returns undefined
|
|
174
|
+
|
|
175
|
+
## [1.8.2] - 2022-05-13
|
|
176
|
+
### Fixed
|
|
177
|
+
- Issue impacting the successful propagation loggers and listeners from a Service definition to Entity children
|
|
178
|
+
|
|
179
|
+
## [1.8.3] - 2022-05-14
|
|
180
|
+
### Changed
|
|
181
|
+
- Removing validation that requires at least one attribute to be provided in a PK composite. This opens the door to static PKs if the user so chooses
|
package/README.md
CHANGED
|
@@ -459,7 +459,7 @@ const EmployeesModel = {
|
|
|
459
459
|
attributes: {
|
|
460
460
|
employee: {
|
|
461
461
|
type: "string",
|
|
462
|
-
default: () =>
|
|
462
|
+
default: () => uuid(),
|
|
463
463
|
},
|
|
464
464
|
firstName: {
|
|
465
465
|
type: "string",
|
|
@@ -686,9 +686,9 @@ attributes: {
|
|
|
686
686
|
Property | Type | Required | Types | Description
|
|
687
687
|
------------ | :--------------------------------------------------------: | :------: | :-------: | -----------
|
|
688
688
|
`type` | `string`, `ReadonlyArray<string>`, `string[]` | yes | all | Accepts the values: `"string"`, `"number"` `"boolean"`, `"map"`, `"list"`, `"set"`, an array of strings representing a finite list of acceptable values: `["option1", "option2", "option3"]`, or `"any"` which disables value type checking on that attribute.
|
|
689
|
-
`required` | `boolean` | no | all | Flag an attribute as required to be present when creating a record. This attribute also acts as a type of `NOT NULL` flag, preventing it from being removed directly.
|
|
689
|
+
`required` | `boolean` | no | all | Flag an attribute as required to be present when creating a record. This attribute also acts as a type of `NOT NULL` flag, preventing it from being removed directly. When applied to nested properties, be mindful that default map values can cause required child attributes to fail validation.
|
|
690
690
|
`hidden` | `boolean` | no | all | Flag an attribute as hidden to remove the property from results before they are returned.
|
|
691
|
-
`default` | `value`, `() => value` | no | all | Either the default value itself or a synchronous function that returns the desired value. Applied before `set` and before `required` check.
|
|
691
|
+
`default` | `value`, `() => value` | no | all | Either the default value itself or a synchronous function that returns the desired value. Applied before `set` and before `required` check. In the case of nested attributes, default values will apply defaults to children attributes until an undefined value is reached
|
|
692
692
|
`validate` | `RegExp`, `(value: any) => void`, `(value: any) => string` | no | all | Either regex or a synchronous callback to return an error string (will result in exception using the string as the error's message), or thrown exception in the event of an error.
|
|
693
693
|
`field` | `string` | no | all | The name of the attribute as it exists in DynamoDB, if named differently in the schema attributes. Defaults to the `AttributeName` as defined in the schema.
|
|
694
694
|
`readOnly` | `boolean` | no | all | Prevents an attribute from being updated after the record has been created. Attributes used in the composition of the table's primary Partition Key and Sort Key are read-only by default. The one exception to `readOnly` is for properties that also use the `watch` property, read [attribute watching](#attribute-watching) for more detail.
|
package/package.json
CHANGED
package/src/entity.js
CHANGED
|
@@ -899,6 +899,18 @@ class Entity {
|
|
|
899
899
|
return {parameters, config};
|
|
900
900
|
}
|
|
901
901
|
|
|
902
|
+
addListeners(logger) {
|
|
903
|
+
this.eventManager.add(logger);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
_addLogger(logger) {
|
|
907
|
+
if (validations.isFunction(logger)) {
|
|
908
|
+
this.addListeners(logger);
|
|
909
|
+
} else {
|
|
910
|
+
throw new e.ElectroError(e.ErrorCodes.InvalidLoggerProvided, `Logger must be of type function`);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
902
914
|
_getPrimaryIndexFieldNames() {
|
|
903
915
|
let hasSortKey = this.model.lookup.indexHasSortKeys[TableIndex];
|
|
904
916
|
let accessPattern = this.model.translations.indexes.fromIndexToAccessPattern[TableIndex];
|
package/src/schema.js
CHANGED
|
@@ -583,7 +583,7 @@ class MapAttribute extends Attribute {
|
|
|
583
583
|
const valueType = getValueType(data);
|
|
584
584
|
|
|
585
585
|
if (data === undefined) {
|
|
586
|
-
data
|
|
586
|
+
return data;
|
|
587
587
|
} else if (valueType !== "object") {
|
|
588
588
|
throw new e.ElectroAttributeValidationError(this.path, `Invalid value type at entity path: "${this.path}". Expected value to be an object to fulfill attribute type "${this.type}"`);
|
|
589
589
|
}
|
package/src/service.js
CHANGED
|
@@ -191,6 +191,14 @@ class Service {
|
|
|
191
191
|
entity._setClient(options.client);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
if (options.logger) {
|
|
195
|
+
entity._addLogger(options.logger);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (options.listeners) {
|
|
199
|
+
entity.addListeners(options.listeners);
|
|
200
|
+
}
|
|
201
|
+
|
|
194
202
|
if (this._modelVersion === ModelVersions.beta && this.service.version) {
|
|
195
203
|
entity.model.version = this.service.version;
|
|
196
204
|
}
|
package/src/validations.js
CHANGED
|
@@ -81,7 +81,6 @@ const Index = {
|
|
|
81
81
|
},
|
|
82
82
|
facets: {
|
|
83
83
|
type: ["array", "string"],
|
|
84
|
-
minItems: 1,
|
|
85
84
|
items: {
|
|
86
85
|
type: "string",
|
|
87
86
|
},
|
|
@@ -89,7 +88,6 @@ const Index = {
|
|
|
89
88
|
},
|
|
90
89
|
composite: {
|
|
91
90
|
type: ["array"],
|
|
92
|
-
minItems: 1,
|
|
93
91
|
items: {
|
|
94
92
|
type: "string",
|
|
95
93
|
},
|