Skip to content

Commit

Permalink
Merge pull request #44 from wmde/snakHash
Browse files Browse the repository at this point in the history
Add support for serialization of snak hashes
  • Loading branch information
thiemowmde authored Sep 4, 2017
2 parents fbc9f67 + 9e4bb6b commit 13ec297
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ version 2.0 of this package:
* Updated the MediaWiki entry point to use the extension.json format.
* Added code sniffers for JavaScript as well as PHP.
* Dropped compatibility with PHP 5.3.
* Added support for deserializing snak hashes.

### 2.0.8 (2016-09-09)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"require": {
"data-values/javascript": "~0.8.0|~0.7.0",
"wikibase/data-model-javascript": "~3.0.0|~2.0.0|~1.0.0"
"wikibase/data-model-javascript": "^3.1.0"
},
"require-dev": {
"wikibase/wikibase-codesniffer": "^0.1.0"
Expand Down
6 changes: 3 additions & 3 deletions src/Deserializers/SnakDeserializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ MODULE.SnakDeserializer = util.inherit( 'WbSnakDeserializer', PARENT, {
*/
deserialize: function( serialization ) {
if( serialization.snaktype === 'novalue' ) {
return new wb.datamodel.PropertyNoValueSnak( serialization.property );
return new wb.datamodel.PropertyNoValueSnak( serialization.property, serialization.hash );
} else if( serialization.snaktype === 'somevalue' ) {
return new wb.datamodel.PropertySomeValueSnak( serialization.property );
return new wb.datamodel.PropertySomeValueSnak( serialization.property, serialization.hash );
} else if( serialization.snaktype === 'value' ) {
var dataValue = null,
type = serialization.datavalue.type,
Expand All @@ -38,7 +38,7 @@ MODULE.SnakDeserializer = util.inherit( 'WbSnakDeserializer', PARENT, {
dataValue = new dv.UnDeserializableValue( value, type, error.message );
}

return new wb.datamodel.PropertyValueSnak( serialization.property, dataValue );
return new wb.datamodel.PropertyValueSnak( serialization.property, dataValue, serialization.hash );
}

throw new Error( 'Incompatible snak type' );
Expand Down
4 changes: 4 additions & 0 deletions src/Serializers/SnakSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ MODULE.SnakSerializer = util.inherit( 'WbSnakSerializer', PARENT, {
property: snak.getPropertyId()
};

if( snak.getHash() !== null ) {
serialization.hash = snak.getHash();
}

if( snak instanceof wikibase.datamodel.PropertyValueSnak ) {
var dataValue = snak.getValue();

Expand Down

0 comments on commit 13ec297

Please sign in to comment.