@@ -3,14 +3,14 @@ import { LoggerFactory } from '../telemetry/LoggerFactory';
33import { Measure } from '../telemetry/TelemetryDecorator' ;
44import { extractErrorMessage } from '../utils/Errors' ;
55import { downloadFile } from './RemoteSchemaHelper' ;
6+ import { SamSchemas , SamSchemasType } from './SamSchemas' ;
67import { SamSchemaTransformer , SamSchema } from './SamSchemaTransformer' ;
78
89const logger = LoggerFactory . getLogger ( 'GetSamSchemaTask' ) ;
910
1011export class GetSamSchemaTask {
1112 private static readonly SAM_SCHEMA_URL =
1213 'https://raw.githubusercontent.com/aws/serverless-application-model/refs/heads/main/schema_source/sam.schema.json' ;
13- private static readonly SAM_SCHEMA_KEY = 'sam-schemas' ;
1414
1515 @Measure ( { name : 'getSamSchema' } )
1616 async run ( dataStore : DataStore ) : Promise < void > {
@@ -22,33 +22,26 @@ export class GetSamSchemaTask {
2222
2323 const resourceSchemas = SamSchemaTransformer . transformSamSchema ( samSchema as unknown as SamSchema ) ;
2424
25- // Store each resource schema individually
26- for ( const [ resourceType , schema ] of resourceSchemas ) {
27- await dataStore . put ( `${ GetSamSchemaTask . SAM_SCHEMA_KEY } :${ resourceType } ` , JSON . stringify ( schema ) ) ;
28- }
25+ // Convert to SamSchemasType format
26+ const schemas = [ ...resourceSchemas . entries ( ) ] . map ( ( [ resourceType , schema ] ) => ( {
27+ name : resourceType ,
28+ content : JSON . stringify ( schema ) ,
29+ createdMs : Date . now ( ) ,
30+ } ) ) ;
31+
32+ const samSchemasData : SamSchemasType = {
33+ version : SamSchemas . V1 ,
34+ schemas : schemas ,
35+ firstCreatedMs : Date . now ( ) ,
36+ lastModifiedMs : Date . now ( ) ,
37+ } ;
38+
39+ await dataStore . put ( 'sam-schemas' , samSchemasData ) ;
2940
3041 logger . info ( `Downloaded and stored ${ resourceSchemas . size } SAM resource schemas` ) ;
3142 } catch ( error ) {
3243 logger . error ( { error : extractErrorMessage ( error ) } , 'Failed to download SAM schema' ) ;
3344 throw error ;
3445 }
3546 }
36-
37- static getSamSchemas ( dataStore : DataStore ) : Map < string , unknown > {
38- const schemas = new Map < string , unknown > ( ) ;
39-
40- // Get all SAM schema keys
41- const keys = dataStore . keys ( 1000 ) ;
42- const samKeys = keys . filter ( ( key : string ) => key . startsWith ( `${ this . SAM_SCHEMA_KEY } :` ) ) ;
43-
44- for ( const key of samKeys ) {
45- const schemaJson = dataStore . get < string > ( key ) ;
46- if ( schemaJson ) {
47- const resourceType = key . replace ( `${ this . SAM_SCHEMA_KEY } :` , '' ) ;
48- schemas . set ( resourceType , JSON . parse ( schemaJson ) as unknown ) ;
49- }
50- }
51-
52- return schemas ;
53- }
5447}
0 commit comments