@@ -71,12 +71,22 @@ export interface RunnerOptions {
7171}
7272
7373export interface RunOptions {
74- client ?: {
75- emit : PDFRunEmitOption
76- }
77- server ?: {
78- path : string
79- }
74+ /**
75+ * Type runner
76+ * @default 'client'
77+ */
78+ type ?: 'client' | 'server'
79+ /**
80+ * Client type format emitter
81+ * @default 'blob'
82+ */
83+ clientEmit ?: PDFRunEmitOption
84+ /**
85+ * Server file destination
86+ *
87+ * Required in {@link RunOptions} type: server
88+ */
89+ serverPath ?: string
8090}
8191
8292/**
@@ -303,8 +313,10 @@ export default class {
303313 *
304314 * @param emit - {@link PDFRunEmitOption}
305315 */
306- public run = ( { client, server } : RunOptions ) : Promise < string > => {
307- this . optionsRun = { client, server }
316+ public run = ( options ?: RunOptions ) : Promise < string > => {
317+ this . optionsRun = options || { }
318+
319+ const runType = options ?. type || 'client'
308320
309321 return new Promise ( async ( res , rej ) => {
310322 if ( ! this . pdfkit ) {
@@ -322,11 +334,12 @@ export default class {
322334 this . globals . __NEW_PAGE__ = true
323335 } )
324336
325- if ( server ) {
337+ if ( runType && options ?. serverPath ) {
326338 this . pdfkit ?. pipe (
327339 createWriteStream (
328340 path . resolve (
329- server . path + `/${ this . options ?. exports ?. name || 'New PDF' } .pdf`
341+ options . serverPath +
342+ `/${ this . options ?. exports ?. name || 'New PDF' } .pdf`
330343 )
331344 )
332345 )
@@ -348,7 +361,7 @@ export default class {
348361 return
349362 }
350363
351- if ( client ) {
364+ if ( runType === ' client' ) {
352365 const stream = this . pdfkit . pipe ( blobStream ( ) )
353366
354367 this . pipeline ( )
@@ -362,7 +375,7 @@ export default class {
362375 } )
363376
364377 stream . on ( 'finish' , ( ) : void => {
365- switch ( client ?. emit ) {
378+ switch ( options ?. clientEmit || 'blob' ) {
366379 case 'blob' :
367380 res ( stream . toBlobURL ( 'application/pdf' ) as string )
368381 break
0 commit comments