@@ -15,6 +15,7 @@ export async function dataInDeployment(
1515 limit : number ;
1616 order : "asc" | "desc" ;
1717 component ?: string ;
18+ format ?: "json" | "jsonArray" | "jsonLines" | "jsonl" | "pretty" ;
1819 } ,
1920) {
2021 if ( options . tableName !== undefined ) {
@@ -27,6 +28,7 @@ export async function dataInDeployment(
2728 limit : options . limit ,
2829 order : options . order as "asc" | "desc" ,
2930 componentPath : options . component ?? "" ,
31+ format : options . format ,
3032 } ,
3133 ) ;
3234 } else {
@@ -72,6 +74,7 @@ async function listDocuments(
7274 limit : number ;
7375 order : "asc" | "desc" ;
7476 componentPath : string ;
77+ format ?: "json" | "jsonArray" | "jsonLines" | "jsonl" | "pretty" ;
7578 } ,
7679) {
7780 const data = ( await runSystemPaginatedQuery ( ctx , {
@@ -91,26 +94,39 @@ async function listDocuments(
9194 return ;
9295 }
9396
94- logDocumentsTable (
95- ctx ,
96- data . slice ( 0 , options . limit ) . map ( ( document ) => {
97- const printed : Record < string , string > = { } ;
98- for ( const key in document ) {
99- printed [ key ] = stringify ( document [ key ] ) ;
100- }
101- return printed ;
102- } ) ,
103- ) ;
104- if ( data . length > options . limit ) {
105- logWarning (
106- chalk . yellow (
107- `Showing the ${ options . limit } ${
108- options . order === "desc" ? "most recently" : "oldest"
109- } created document${
110- options . limit > 1 ? "s" : ""
111- } . Use the --limit option to see more.`,
112- ) ,
97+ if ( options . format === "json" || options . format === "jsonArray" ) {
98+ logOutput (
99+ "[\n" + data . slice ( 0 , options . limit ) . map ( stringify ) . join ( ",\n" ) + "\n]" ,
100+ ) ;
101+ } else if ( options . format === "jsonLines" || options . format === "jsonl" ) {
102+ logOutput (
103+ data
104+ . slice ( 0 , options . limit )
105+ . map ( ( document ) => stringify ( document ) )
106+ . join ( "\n" ) ,
107+ ) ;
108+ } else {
109+ logDocumentsTable (
110+ ctx ,
111+ data . slice ( 0 , options . limit ) . map ( ( document ) => {
112+ const printed : Record < string , string > = { } ;
113+ for ( const key in document ) {
114+ printed [ key ] = stringify ( document [ key ] ) ;
115+ }
116+ return printed ;
117+ } ) ,
113118 ) ;
119+ if ( data . length > options . limit ) {
120+ logWarning (
121+ chalk . yellow (
122+ `Showing the ${ options . limit } ${
123+ options . order === "desc" ? "most recently" : "oldest"
124+ } created document${
125+ options . limit > 1 ? "s" : ""
126+ } . Use the --limit option to see more.`,
127+ ) ,
128+ ) ;
129+ }
114130 }
115131}
116132
0 commit comments