@@ -15,6 +15,7 @@ export async function dataInDeployment(
15
15
limit : number ;
16
16
order : "asc" | "desc" ;
17
17
component ?: string ;
18
+ format ?: "json" | "jsonArray" | "jsonLines" | "jsonl" | "pretty" ;
18
19
} ,
19
20
) {
20
21
if ( options . tableName !== undefined ) {
@@ -27,6 +28,7 @@ export async function dataInDeployment(
27
28
limit : options . limit ,
28
29
order : options . order as "asc" | "desc" ,
29
30
componentPath : options . component ?? "" ,
31
+ format : options . format ,
30
32
} ,
31
33
) ;
32
34
} else {
@@ -72,6 +74,7 @@ async function listDocuments(
72
74
limit : number ;
73
75
order : "asc" | "desc" ;
74
76
componentPath : string ;
77
+ format ?: "json" | "jsonArray" | "jsonLines" | "jsonl" | "pretty" ;
75
78
} ,
76
79
) {
77
80
const data = ( await runSystemPaginatedQuery ( ctx , {
@@ -91,26 +94,39 @@ async function listDocuments(
91
94
return ;
92
95
}
93
96
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
+ } ) ,
113
118
) ;
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
+ }
114
130
}
115
131
}
116
132
0 commit comments