license import { ARArtifact } from './schema/extension-ar-artifacts.js' ; import { JsonLd } from './schema/json-ld.js' ; import { flatMap } from '../utils/flat-map.js' ; export class ArtifactDecoder { decode ( jsonld ) { return this . decodeUnknown ( jsonld ) ; } private decodeUnknown ( jsonld ) { if ( Array . isArray ( jsonld ) ) { return this . decodeArray ( jsonld ) ; } if ( ! ( '@type' in jsonld ) || typeof jsonld [ '@type' ] !== 'string' ) { return [ ] ; } switch ( jsonld [ '@type' ] as string ) { case 'DataFeed' : return this . decodeDataFeed ( jsonld ) ; case 'ARArtifact' : return this . decodeArArtifact ( jsonld ) ; default : return [ ] ; } } private decodeArray ( arr ) { return flatMap ( arr , e => this . decodeUnknown ( e ) ) ; } private decodeDataFeed ( jsonld ) { const elements = jsonld . dataFeedElement ; if ( ! elements ) { return [ ] ; } if ( ! Array . isArray ( elements ) ) { return this . decodeUnknown ( elements ) ; } return this . decodeArray ( elements ) ; } private decodeArArtifact ( jsonld ) { return [ jsonld as ARArtifact ] ; } }