File tree Expand file tree Collapse file tree 4 files changed +46
-11
lines changed
data-core/lib/plugin-utils Expand file tree Collapse file tree 4 files changed +46
-11
lines changed Original file line number Diff line number Diff line change 11/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
22
3- import { SchemaField } from '../schema/types' ;
3+ import { SchemaField , SchemaFieldObject } from '../schema/types' ;
4+
5+ export type PluginEditSchema =
6+ | ( SchemaFieldObject & { type : 'root' } )
7+ | undefined
8+ | symbol ;
49
510export abstract class Plugin {
611 static HIDDEN = Symbol ( 'hidden' ) ;
712
813 name : string = 'Plugin' ;
914
10- watchFields ?: string [ ] = [ ] ;
11-
1215 init ( data : any ) { }
1316
14- editSchema ( formData ?: any ) : SchemaField | undefined | symbol {
17+ editSchema ( formData ?: any ) : PluginEditSchema {
1518 return undefined ;
1619 }
1720
Original file line number Diff line number Diff line change 1- import { Plugin , SchemaFieldObject } from '@stac-manager/data-core' ;
2- import { array2Object , object2Array } from '../utils' ;
1+ import { Plugin , PluginEditSchema } from '@stac-manager/data-core' ;
2+ import { array2Object , hasExtension , object2Array } from '../utils' ;
33
44export class PluginItemAssets extends Plugin {
5- name = 'Item Assets' ;
5+ name = 'Item Assets Extension' ;
6+
7+ editSchema ( data : any ) : PluginEditSchema {
8+ if ( ! hasExtension ( data , 'item-assets' ) ) {
9+ return Plugin . HIDDEN ;
10+ }
611
7- editSchema ( ) : SchemaFieldObject {
812 return {
913 type : 'root' ,
1014 properties : {
Original file line number Diff line number Diff line change 1- import { Plugin , SchemaFieldObject } from '@stac-manager/data-core' ;
1+ import { Plugin , PluginEditSchema } from '@stac-manager/data-core' ;
22import {
33 array2Object ,
4+ hasExtension ,
45 object2Array ,
56 object2Tuple ,
67 tuple2Object
78} from '../utils' ;
89
910export class PluginRender extends Plugin {
10- name = 'Render' ;
11+ name = 'Render Extension' ;
12+
13+ editSchema ( data : any ) : PluginEditSchema {
14+ if ( ! hasExtension ( data , 'render' ) ) {
15+ return Plugin . HIDDEN ;
16+ }
1117
12- editSchema ( ) : SchemaFieldObject {
1318 return {
1419 type : 'root' ,
1520 properties : {
Original file line number Diff line number Diff line change @@ -170,3 +170,26 @@ export function tuple2Object(stack: string[][]) {
170170 return { ...acc , [ key ] : item } ;
171171 } , { } ) ;
172172}
173+
174+ /**
175+ * Checks if the given data has a specific STAC extension.
176+ *
177+ * @param data - The data object to check for the extension.
178+ * @param extension - The name of the extension to look for.
179+ * @param version - An optional function that takes a version string and returns
180+ * a boolean indicating whether the version matches.
181+ *
182+ * @returns A boolean indicating whether the specified extension (and version,
183+ * if provided) is present in the data.
184+ */
185+ export function hasExtension (
186+ data : any ,
187+ extension : string ,
188+ version ?: ( v : string ) => boolean
189+ ) {
190+ const regex = new RegExp ( `/${ extension } /v([0-9.]+)/schema.json` ) ;
191+ return data ?. stac_extensions ?. some ( ( ext : string ) => {
192+ const match = ext . match ( regex ) ;
193+ return match && ( ! version || version ( match [ 1 ] ) ) ;
194+ } ) ;
195+ }
You can’t perform that action at this time.
0 commit comments