Skip to content

Commit

Permalink
Merge 76b9f01 into eba39d7
Browse files Browse the repository at this point in the history
  • Loading branch information
mathe42 committed Apr 23, 2020
2 parents eba39d7 + 76b9f01 commit 92b1628
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,39 @@ const DEBUG = process.env.DEBUG_DOCX_TEMPLATES;
// ==========================================
// Main
// ==========================================
/**
* Create Report from docx template
*
* example:
* ```js
* createReport({
* template,
* data: query => graphqlServer.execute(query),
* additionalJsContext: {
* // all of these will be available to JS snippets in your template commands
* foo: 'bar',
* qrCode: async url => {
* // do stuff
* },
* },
* cmdDelimiter: '+++',
* literalXmlDelimiter: '||',
* processLineBreaks: true,
* noSandbox: false,
* });
* ```
*
* @param options Options for Report
*/
async function createReport(options: UserOptions): Promise<Uint8Array>;
/**
* For development and testing dont use _probe if you don't know what you are doing
*/
async function createReport(options: UserOptions, _probe: 'JS'): Promise<Node>;

/**
* For development and testing dont use _probe if you don't know what you are doing
*/
async function createReport(
options: UserOptions,
_probe: 'XML'
Expand Down
36 changes: 36 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,50 @@ type RunJSFunc = (o: {
};

export type UserOptions = {
/**
* template as a NodeJS Buffer or Buffer like Object
*/
template: Buffer;
/**
* Object of Data to be injected or a (async) Function that resolves to the Data. The function gets as a Argument the contens of the QUERY Command
*/
data?: ReportData | QueryResolver;
/**
* TODO: dont know what this option is for
*/
queryVars?: any;
/**
* Define a custom Command delimeter this can be a String e.g. '+++' or a Array of Strings with length 2: ['{', '}'] with first element as the start delimeter and the scond as the end delimeter
*/
cmdDelimiter?: string | [string, string];
/**
* TODO: dont know what this option is for
*/
literalXmlDelimiter?: string;
/**
* TODO: dont know what this option is for
*/
processLineBreaks?: boolean; // true by default
/**
* Template and data is SAVE and TRUSTED. Set this option to true to disable running all Commands in a new JS vm.
*/
noSandbox?: boolean;
/**
* Custom Sandbox Options see Documentation for mor details
*/
runJs?: RunJSFunc;
/**
* Add Function or other static Data to this option to have access to it in your commands
* ```js
* additionalJsContext: {
* qrCode: url => {
* const dataUrl = createQrImage(url, { size: 500 });
* const data = dataUrl.slice('data:image/gif;base64,'.length);
* return { width: 6, height: 6, data, extension: '.gif' };
* },
* }
* ```
*/
additionalJsContext?: Object;
};

Expand Down

0 comments on commit 92b1628

Please sign in to comment.