@@ -34,6 +34,31 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
34
34
* `displayName` was specified in the API spec for this property.
35
35
*/
36
36
propertyName : { type : String } ,
37
+ /**
38
+ * A type size.
39
+ * Is only used for async / avro api
40
+ */
41
+ size : { type : String } ,
42
+ /**
43
+ * A type defaultValue.
44
+ * Is only used for async / avro api
45
+ */
46
+ defaultValue : { type : String } ,
47
+ /**
48
+ * A type namespace.
49
+ * Is only used for async / avro api
50
+ */
51
+ namespace : { type : String } ,
52
+ /**
53
+ * A type aliases.
54
+ * Is only used for async / avro api
55
+ */
56
+ aliases : { type : Array } ,
57
+ /**
58
+ * Avro original value type.
59
+ * Is only used for async / avro api
60
+ */
61
+ avroValue : { type : String } ,
37
62
/**
38
63
* Computed value, true if `displayName` has been defined for this
39
64
* property.
@@ -211,6 +236,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
211
236
212
237
constructor ( ) {
213
238
super ( ) ;
239
+ this . avroValue = undefined
240
+ this . defaultValue = undefined
241
+ this . size = undefined
242
+ this . namespace = undefined
243
+ this . aliases = undefined
214
244
this . hasDisplayName = false ;
215
245
this . hasParentTypeName = false ;
216
246
this . hasPropertyDescription = false ;
@@ -290,6 +320,14 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
290
320
_shapeRangeChanged ( shape , range ) {
291
321
this . displayName = this . _computeDisplayName ( range , shape ) ;
292
322
this . propertyName = this . _computePropertyName ( range , shape ) ;
323
+ this . avroValue = this . _computeAvroShapeRangeSourceMap ( range , shape )
324
+ const { size, namespace, aliases, defaultValue} = this . _computeAvroProperties ( range , shape )
325
+ this . size = size
326
+ this . namespace = namespace
327
+ this . aliases = aliases
328
+ this . defaultValue = defaultValue
329
+
330
+
293
331
this . hasDisplayName = this . _computeHasDisplayName (
294
332
this . displayName ,
295
333
this . propertyName
@@ -369,6 +407,119 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
369
407
return undefined ;
370
408
}
371
409
410
+ /**
411
+ * Computes avro property. Only for async / avro
412
+ *
413
+ * @param {Object } range Range object of current shape.
414
+ * @param {Object } shape The shape object
415
+ * @return {String|undefined } Size of the property
416
+ */
417
+ _computeAvroProperty ( range , shape , prop ) {
418
+ if ( ! shape && ! range ) {
419
+ return undefined ;
420
+ }
421
+ let result
422
+ if ( shape ) {
423
+ shape = this . _resolve ( shape ) ;
424
+ result = /** @type string */ ( this . _getValue (
425
+ shape ,
426
+ this . ns . aml . vocabularies . shapes [ prop ]
427
+ ) ) ;
428
+
429
+ }
430
+ if ( range && ! result ) {
431
+ range = this . _resolve ( range ) ;
432
+ result = this . _getValue ( range , this . ns . aml . vocabularies . shapes [ prop ] ) ;
433
+ }
434
+ return result ? String ( result ) : undefined ;
435
+ }
436
+
437
+ /**
438
+ * Computes avro defaultValue. Only for async / avro
439
+ *
440
+ * @param {Object } range Range object of current shape.
441
+ * @param {Object } shape The shape object
442
+ * @return {String|undefined } Size of the property
443
+ */
444
+ _computeAvroDefaultValue ( range , shape ) {
445
+ if ( ! shape && ! range ) {
446
+ return undefined ;
447
+ }
448
+ const defaultValueKey = this . ns . w3 . shacl . defaultValue
449
+ let result
450
+ if ( shape ) {
451
+ shape = this . _resolve ( shape ) ;
452
+ if ( shape [ defaultValueKey ] ) {
453
+ result = this . _getValue ( shape [ defaultValueKey ] [ 0 ] , this . ns . aml . vocabularies . data . value )
454
+ }
455
+ }
456
+ if ( range && ! result ) {
457
+ range = this . _resolve ( range ) ;
458
+ if ( range [ defaultValueKey ] ) {
459
+ result = this . _getValue ( range [ defaultValueKey ] , this . ns . aml . vocabularies . data . value )
460
+ }
461
+ }
462
+ return result ? String ( result ) : undefined ;
463
+ }
464
+
465
+ /**
466
+ * Computes size of the property. Only for async / avro
467
+ *
468
+ * @param {Object } range Range object of current shape.
469
+ * @param {Object } shape The shape object
470
+ * @return {Object|undefined } Size,namespace,aliases,defaultValue of the property (only when has avroValues)
471
+ */
472
+ _computeAvroProperties ( range , shape ) {
473
+ if ( ! this . avroValue ) {
474
+ return { size :undefined , namespace :undefined , aliases :undefined , defaultValue :undefined }
475
+ }
476
+ const size = this . _computeAvroProperty ( range , shape , "size" )
477
+ const namespace = this . _computeAvroProperty ( range , shape , "namespace" )
478
+ const aliases = this . _computeAvroProperty ( range , shape , "aliases" )
479
+ const defaultValue = this . _computeAvroDefaultValue ( range , shape )
480
+ return { size, namespace, aliases, defaultValue}
481
+ }
482
+
483
+ /**
484
+ * Computes source values of the property. Only for async / avro
485
+ *
486
+ * @param {Object } data Range object of current shape.
487
+ */
488
+ _computeAvroSourceMap ( data ) {
489
+ try {
490
+ const sourcesKey = this . _getAmfKey ( this . ns . aml . vocabularies . docSourceMaps . sources )
491
+ const avroSchemaKey = this . _getAmfKey ( this . ns . aml . vocabularies . docSourceMaps . avroSchema )
492
+ const valueKey = this . _getAmfKey ( this . ns . aml . vocabularies . docSourceMaps . value )
493
+ if ( data [ sourcesKey ] && data [ sourcesKey ] [ 0 ] [ avroSchemaKey ] ) {
494
+ const avroValues = this . _ensureArray ( data [ sourcesKey ] [ 0 ] [ avroSchemaKey ] )
495
+ return avroValues [ 0 ] [ valueKey ] [ 0 ] [ '@value' ]
496
+ }
497
+ return undefined
498
+ } catch ( _ ) {
499
+ return undefined
500
+ }
501
+
502
+ }
503
+
504
+ /**
505
+ * Computes source values of the property. Only for async / avro
506
+ *
507
+ * @param {Object } range Range object of current shape.
508
+ * @param {Object } shape The shape object
509
+ * @return {Object } Size of the property
510
+ */
511
+ _computeAvroShapeRangeSourceMap ( range , shape ) {
512
+ const shapeValue = this . _computeAvroSourceMap ( shape )
513
+ if ( shapeValue ) {
514
+ return shapeValue
515
+ }
516
+ return this . _computeAvroSourceMap ( range )
517
+ }
518
+
519
+
520
+
521
+
522
+
372
523
/**
373
524
* Computes value for `hasDisplayName` property.
374
525
* Indicates that `displayName` has been defined in the API specification.
@@ -613,9 +764,64 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
613
764
const itemType = this . arrayScalarTypeName ;
614
765
dataType = `${ dataType } of ${ itemType } ` ;
615
766
}
616
- return html `< span class ="data-type "> ${ dataType } </ span > ` ;
767
+ return html `
768
+ < span class ="data-type "> ${ dataType } </ span > ` ;
769
+
617
770
}
618
771
772
+ /**
773
+ * @return {TemplateResult | String } Template size value (only for async / avro)
774
+ */
775
+ _getFixedTypeSizeAvroTemplate ( ) {
776
+ const { size } = this ;
777
+ if ( ! size ) {
778
+ return ''
779
+ }
780
+ return html `
781
+ < div class ="fixed-type-size "> < span > Size: ${ size } </ span > </ div > ` ;
782
+ }
783
+
784
+ /**
785
+ * @return {TemplateResult | String } Template size value (only for async / avro)
786
+ */
787
+ _getDefaultValueAvroTemplate ( ) {
788
+ const { defaultValue } = this ;
789
+ if ( ! defaultValue ) {
790
+ return ''
791
+ }
792
+ return html `
793
+ < div class ="fixed-type-size "> < span > Default Value: ${ defaultValue } </ span > </ div > ` ;
794
+ }
795
+
796
+ /**
797
+ * @return {TemplateResult | String } Template namespace value (only for async / avro)
798
+ */
799
+ _getTypeNamespaceAvroTemplate ( ) {
800
+ const { namespace } = this ;
801
+ if ( ! namespace ) {
802
+ return ''
803
+ }
804
+ return html `
805
+ < div class ="fixed-type-size "> < span > Namespace: ${ namespace } </ span > </ div > ` ;
806
+ }
807
+
808
+ /**
809
+ * @return {TemplateResult | String } Template namespace value (only for async / avro)
810
+ */
811
+ _getTypeAliasesAvroTemplate ( ) {
812
+ const { aliases } = this ;
813
+ if ( ! aliases ) {
814
+ return '' ;
815
+ }
816
+ return html `
817
+ < div class ="fixed-type-size ">
818
+ Aliases: ${ aliases . map ( alias => html `< span > ${ alias } </ span > ` ) }
819
+ </ div >
820
+ ` ;
821
+ }
822
+
823
+
824
+
619
825
/**
620
826
* @return {TemplateResult|string } Template for the description
621
827
*/
@@ -716,6 +922,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
716
922
> `
717
923
: '' }
718
924
</ div >
925
+ ${ this . _getDefaultValueAvroTemplate ( ) }
926
+ ${ this . _getFixedTypeSizeAvroTemplate ( ) }
927
+ ${ this . _getTypeNamespaceAvroTemplate ( ) }
928
+ ${ this . _getTypeAliasesAvroTemplate ( ) }
719
929
${ this . _deprecatedWarningTemplate ( ) }
720
930
${ this . _descriptionTemplate ( ) }
721
931
< property-range-document
0 commit comments