@@ -9,17 +9,18 @@ import {
99 ImportRequestSchema ,
1010} from "@aserto/node-directory/src/gen/cjs/aserto/directory/importer/v3/importer_pb" ;
1111import {
12+ MetadataSchema ,
1213 Model ,
1314 SetManifestRequestSchema ,
1415} from "@aserto/node-directory/src/gen/cjs/aserto/directory/model/v3/model_pb" ;
1516import {
1617 Body ,
1718 DeleteManifestRequest ,
18- GetManifestRequest ,
1919 Metadata ,
2020} from "@aserto/node-directory/src/gen/cjs/aserto/directory/model/v3/model_pb" ;
2121import {
2222 CheckRequestSchema ,
23+ ChecksRequestSchema ,
2324 GetGraphRequestSchema ,
2425 GetObjectManyRequestSchema ,
2526 GetObjectRequestSchema ,
@@ -63,6 +64,8 @@ import { DsRegistry } from "./serializer";
6364import {
6465 CheckRequest ,
6566 CheckResponse ,
67+ ChecksRequest ,
68+ ChecksResponse ,
6669 DeleteManifestResponse ,
6770 DeleteObjectRequest ,
6871 DeleteObjectResponse ,
@@ -73,6 +76,7 @@ import {
7376 ExportResponse ,
7477 GetGraphRequest ,
7578 GetGraphResponse ,
79+ GetManifestRequest ,
7680 GetManifestResponse ,
7781 GetObjectManyRequest ,
7882 GetObjectManyResponse ,
@@ -129,6 +133,18 @@ export enum ImportMsgCase {
129133
130134const ADDRESS_REGEX = / h t t p s ? : \/ \/ / ;
131135
136+ export const HEADER_ASERTO_MANIFEST_REQUEST =
137+ "Aserto-Manifest-Request" as const ;
138+
139+ // Return the manifest metadata and body.
140+ export const MANIFEST_REQUEST_DEFAULT = "" as const ;
141+ // Only return the manifest metadata.
142+ export const MANIFEST_REQUEST_METADATA_ONLY = "metadata-only" as const ;
143+ // Only return the manifest metadata and model.
144+ export const MANIFEST_REQUEST_MODEL_ONLY = "model-only" as const ;
145+ // Return the manifest metadata, body, and model.
146+ export const MANIFEST_REQUEST_WITH_MODEL = "with-model" as const ;
147+
132148export class DirectoryV3 {
133149 ReaderClient : Client < typeof Reader > ;
134150 WriterClient : Client < typeof Writer > ;
@@ -313,6 +329,22 @@ export class DirectoryV3 {
313329 }
314330 }
315331
332+ async checks (
333+ params : ChecksRequest ,
334+ options ?: CallOptions ,
335+ ) : Promise < ChecksResponse > {
336+ try {
337+ const response = await this . ReaderClient . checks (
338+ create ( ChecksRequestSchema , params ) ,
339+ options ,
340+ ) ;
341+
342+ return this . registry . serializeResponse ( response ) ;
343+ } catch ( error ) {
344+ throw handleError ( error , "checks" ) ;
345+ }
346+ }
347+
316348 async object (
317349 params : GetObjectRequest ,
318350 options ?: CallOptions ,
@@ -526,28 +558,51 @@ export class DirectoryV3 {
526558 } ;
527559 } ) ;
528560
529- const bodyData = data
561+ return this . buildManifestResponse ( data ) ;
562+ } catch ( error ) {
563+ throw handleError ( error , "getManifest" ) ;
564+ }
565+ }
566+
567+ private buildManifestResponse (
568+ data : { [ x : string ] : JsonObject | Metadata | Body | undefined } [ ] ,
569+ ) {
570+ let bodyData : Uint8Array [ ] = [ new Uint8Array ( ) ] ;
571+ let modelData : JsonObject = { } ;
572+ let metadata : Metadata = create ( MetadataSchema , { } ) ;
573+ let body : string = "" ;
574+
575+ metadata = data [ 0 ] ?. metadata as Metadata ;
576+
577+ bodyData = data
578+ . map ( ( el ) => {
579+ return el [ "body" ] ;
580+ } )
581+ . filter ( ( el ) => el !== undefined )
582+ . map ( ( el ) => {
583+ return ( el as Body ) ?. data ;
584+ } ) ;
585+
586+ body = new TextDecoder ( ) . decode ( mergeUint8Arrays ( ...bodyData ) ) ;
587+
588+ modelData =
589+ data
530590 . map ( ( el ) => {
531- return el [ "body " ] ;
591+ return el [ "model " ] ;
532592 } )
533593 . filter ( ( el ) => el !== undefined )
534594 . map ( ( el ) => {
535- return ( el as Body ) ?. data ;
536- } ) ;
537-
538- const body = new TextDecoder ( ) . decode ( mergeUint8Arrays ( ...bodyData ) ) ;
539- const metadata = data [ 0 ] ?. metadata as Metadata ;
540-
541- return {
542- body,
543- updatedAt : metadata ?. updatedAt
544- ? this . registry . serializeResponse ( metadata ?. updatedAt )
545- : undefined ,
546- etag : metadata ?. etag ,
547- } ;
548- } catch ( error ) {
549- throw handleError ( error , "getManifest" ) ;
550- }
595+ return el as JsonObject ;
596+ } ) ?. [ 0 ] || { } ;
597+
598+ return {
599+ body,
600+ model : modelData ,
601+ updatedAt : metadata ?. updatedAt
602+ ? this . registry . serializeResponse ( metadata ?. updatedAt )
603+ : undefined ,
604+ etag : metadata ?. etag ,
605+ } ;
551606 }
552607
553608 async setManifest (
0 commit comments