Skip to content

Add support for serialization of snak hashes #44

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

Merged
merged 1 commit into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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