@@ -8,6 +8,10 @@ const graphTypes = require('./graphTypes');
8
8
const types = require ( './types' ) ;
9
9
const util = require ( './util' ) ;
10
10
11
+ const {
12
+ handleEvent : _handleEvent
13
+ } = require ( './events' ) ;
14
+
11
15
// constants
12
16
const {
13
17
// RDF,
@@ -44,15 +48,16 @@ module.exports = api;
44
48
*/
45
49
api . fromRDF = async (
46
50
dataset ,
47
- {
48
- useRdfType = false ,
49
- useNativeTypes = false ,
50
- rdfDirection = null
51
- }
51
+ options
52
52
) => {
53
53
const defaultGraph = { } ;
54
54
const graphMap = { '@default' : defaultGraph } ;
55
55
const referencedOnce = { } ;
56
+ const {
57
+ useRdfType = false ,
58
+ useNativeTypes = false ,
59
+ rdfDirection = null
60
+ } = options ;
56
61
57
62
for ( const quad of dataset ) {
58
63
// TODO: change 'name' to 'graph'
@@ -87,7 +92,7 @@ api.fromRDF = async (
87
92
continue ;
88
93
}
89
94
90
- const value = _RDFToObject ( o , useNativeTypes , rdfDirection ) ;
95
+ const value = _RDFToObject ( o , useNativeTypes , rdfDirection , options ) ;
91
96
util . addValue ( node , p , value , { propertyIsArray : true } ) ;
92
97
93
98
// object may be an RDF list/partial list node but we can't know easily
@@ -275,10 +280,12 @@ api.fromRDF = async (
275
280
*
276
281
* @param o the RDF triple object to convert.
277
282
* @param useNativeTypes true to output native types, false not to.
283
+ * @param rdfDirection text direction mode [null, i18n-datatype]
284
+ * @param options top level API options
278
285
*
279
286
* @return the JSON-LD object.
280
287
*/
281
- function _RDFToObject ( o , useNativeTypes , rdfDirection ) {
288
+ function _RDFToObject ( o , useNativeTypes , rdfDirection , options ) {
282
289
// convert NamedNode/BlankNode object to JSON-LD
283
290
if ( o . termType . endsWith ( 'Node' ) ) {
284
291
return { '@id' : o . value } ;
@@ -334,7 +341,17 @@ function _RDFToObject(o, useNativeTypes, rdfDirection) {
334
341
if ( language . length > 0 ) {
335
342
rval [ '@language' ] = language ;
336
343
if ( ! language . match ( REGEX_BCP47 ) ) {
337
- console . warn ( `@language must be valid BCP47: ${ language } ` ) ;
344
+ _handleEvent ( {
345
+ event : {
346
+ code : 'invalid @language value' ,
347
+ level : 'warning' ,
348
+ message : '@language value must be valid BCP47.' ,
349
+ details : {
350
+ language
351
+ }
352
+ } ,
353
+ options
354
+ } ) ;
338
355
}
339
356
}
340
357
rval [ '@direction' ] = direction ;
0 commit comments