-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(map): add serialisation for map<string, string> #654
Changes from all commits
f9d6f68
489f5df
4963868
e71c4c7
b8d31ba
877f844
f0de781
b82f74a
b4519ae
5ec493e
a6c87fa
edf17d7
203b7c8
ec54e4c
b01aec7
ef1dbd9
f44f9f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,9 @@ class ResourceValidator { | |
return this.visitEnumDeclaration(thing, parameters); | ||
} else if (thing.isClassDeclaration?.()) { | ||
return this.visitClassDeclaration(thing, parameters); | ||
} else if (thing.isRelationship?.()) { | ||
} else if (thing.isMapDeclaration?.()) { | ||
return this.visitMapDeclaration(thing, parameters); | ||
}else if (thing.isRelationship?.()) { | ||
return this.visitRelationshipDeclaration(thing, parameters); | ||
} else if (thing.isTypeScalar?.()) { | ||
return this.visitField(thing.getScalarField(), parameters); | ||
|
@@ -104,6 +106,36 @@ class ResourceValidator { | |
return null; | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* | ||
* @param {MapDeclaration} mapDeclaration - the object being visited | ||
* @param {Object} parameters - the parameter | ||
* @private | ||
*/ | ||
visitMapDeclaration(mapDeclaration, parameters) { | ||
const obj = parameters.stack.pop(); | ||
|
||
if (!((obj.value instanceof Map))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not want to accept simple JS objects, indexed as Maps? I think this will force users to create Maps in their code rather than just JS objects. |
||
throw new Error('Expected a Map, but found ' + JSON.stringify(obj)); | ||
} | ||
|
||
if (obj.$class !== mapDeclaration.getFullyQualifiedName()) { | ||
throw new Error(`$class value must match ${mapDeclaration.getFullyQualifiedName()}`); | ||
} | ||
|
||
obj.value.forEach((value, key) => { | ||
if(!ModelUtil.isSystemProperty(key)) { | ||
if (typeof key !== 'string') { | ||
ResourceValidator.reportInvalidMap(parameters.rootResourceIdentifier, mapDeclaration, obj); | ||
} | ||
if (typeof value !== 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only support values that are Strings? |
||
ResourceValidator.reportInvalidMap(parameters.rootResourceIdentifier, mapDeclaration, obj); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* @param {ClassDeclaration} classDeclaration - the object being visited | ||
|
@@ -450,7 +482,7 @@ class ResourceValidator { | |
/** | ||
* Throw a new error for a model violation. | ||
* @param {string} id - the identifier of this instance. | ||
* @param {classDeclaration} classDeclaration - the declaration of the classs | ||
* @param {ClassDeclaration} classDeclaration - the declaration of the class | ||
* @param {Object} value - the value of the field. | ||
* @private | ||
*/ | ||
|
@@ -466,7 +498,23 @@ class ResourceValidator { | |
/** | ||
* Throw a new error for a model violation. | ||
* @param {string} id - the identifier of this instance. | ||
* @param {RelationshipDeclaration} relationshipDeclaration - the declaration of the classs | ||
* @param {MapDeclaration} mapDeclaration - the declaration of the map | ||
* @param {Object} value - the value of the field. | ||
* @private | ||
*/ | ||
static reportInvalidMap(id, mapDeclaration, value) { | ||
let formatter = Globalize.messageFormatter('resourcevalidator-invalidmap'); | ||
throw new ValidationException(formatter({ | ||
resourceId: id, | ||
classFQN: mapDeclaration.getFullyQualifiedName(), | ||
invalidValue: value.toString() | ||
})); | ||
} | ||
|
||
/** | ||
* Throw a new error for a model violation. | ||
* @param {string} id - the identifier of this instance. | ||
* @param {RelationshipDeclaration} relationshipDeclaration - the declaration of the class | ||
* @param {Object} value - the value of the field. | ||
* @private | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to loosen this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MapDeclaration doesn't implement
isTransaction()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it should? we could move the function to the
Declaration
class?