UNPKG

22.7 kBMarkdownView Raw
1## Classes
2
3<dl>
4<dt><a href="#HTML_ADAPTER">HTML_ADAPTER</a> : <code>HTML_Adapter</code></dt>
5<dd><p>HTML response adapter class which renders templates from provided data and template names</p>
6</dd>
7<dt><a href="#JSON_ADAPTER">JSON_ADAPTER</a> : <code>JSON_Adapter</code></dt>
8<dd><p>Baseline adapter class which handles wrapping response data in an object with a status code and result message. Formatting is configurable both for success and error responses</p>
9</dd>
10<dt><a href="#XML_ADAPTER">XML_ADAPTER</a> : <code>XML_Adapter</code></dt>
11<dd><p>XML response adapter class which handles wrapping response data in object with status code and result message and converting into XML string.</p>
12</dd>
13<dt><a href="#CONTENT_ADAPTER_INTERFACE">CONTENT_ADAPTER_INTERFACE</a></dt>
14<dd></dd>
15</dl>
16
17## Functions
18
19<dl>
20<dt><a href="#findValidViewFromPaths">findValidViewFromPaths(_default, [dirs])</a><code>Object</code></dt>
21<dd><p>Iterates through an array of file paths resolving after it finds a valid path or resolves with the default value</p>
22</dd>
23<dt><a href="#_RENDER">_RENDER(data, options, cb)</a></dt>
24<dd><p>Renders an HTML string from provided data</p>
25</dd>
26<dt><a href="#_ERROR">_ERROR(err, options, cb)</a></dt>
27<dd><p>Renders an HTML error page template</p>
28</dd>
29<dt><a href="#_RENDER">_RENDER(data, options)</a><code>Object</code></dt>
30<dd><p>Creates a formatted success response object</p>
31</dd>
32<dt><a href="#_ERROR">_ERROR(err, options)</a><code>Object</code></dt>
33<dd><p>Creates a formatted error response object</p>
34</dd>
35<dt><a href="#_RENDER">_RENDER(data, options)</a><code>string</code></dt>
36<dd><p>Creates a formatted success message and converts to XML</p>
37</dd>
38<dt><a href="#_ERROR">_ERROR(err, options)</a><code>string</code></dt>
39<dd><p>Creates a formatted error response message and converts to XML</p>
40</dd>
41</dl>
42
43<a name="HTML_ADAPTER"></a>
44
45## HTML_ADAPTER : <code>HTML_Adapter</code>
46HTML response adapter class which renders templates from provided data and template names
47
48**Kind**: global class
49**Extends:** <code>JSON_Adapter</code>
50
51* [HTML_ADAPTER](#HTML_ADAPTER) : <code>HTML_Adapter</code>
52 * [new HTML_ADAPTER(options)](#new_HTML_ADAPTER_new)
53 * [.render(data, [options], cb)](#HTML_ADAPTER+render) ⇒ <code>Object</code>
54 * [.error(err, [options], cb)](#HTML_ADAPTER+error) ⇒ <code>Object</code>
55
56<a name="new_HTML_ADAPTER_new"></a>
57
58### new HTML_ADAPTER(options)
59
60| Param | Type | Default | Description |
61| --- | --- | --- | --- |
62| options | <code>Object</code> | | Configurable options for HTML adapter |
63| [options.engine] | <code>Object</code> | <code>ejs</code> | Defines which templating engine to use when rendering template files |
64| options.engine.render | <code>function</code> | | If providing a custom rendering engine module must include a .render function which is synchronous or returns a Promise. Render function should also expect the following arguments in this order: (template_string, template_data, options) |
65| [options.engine_configuration] | <code>Object</code> | | Defines a default set of configuration options that are passed to the rendering function |
66| [options.extname] | <code>string</code> | | Name of a periodicjs extension. Used in finding valid template |
67| [options.themename] | <code>string</code> | <code>&quot;\&quot;periodicjs.theme.default\&quot;&quot;</code> | Name of a periodicjs theme. Used in finding valid template |
68| [options.locals] | <code>Object</code> | <code>{}</code> | Shared local values for rendering. Only used when express rendering is not available. |
69| [options.viewname] | <code>string</code> | | Defines a default view name that should be used in rendering |
70| [options.fileext] | <code>string</code> | <code>&quot;\&quot;.ejs\&quot;&quot;</code> | Defines the default extension name of the template file |
71
72<a name="HTML_ADAPTER+render"></a>
73
74### htmL_ADAPTER.render(data, [options], cb) ⇒ <code>Object</code>
75Renders HTML from provided data and template
76
77**Kind**: instance method of <code>[HTML_ADAPTER](#HTML_ADAPTER)</code>
78**Returns**: <code>Object</code> - Returns a Promise if cb arguement is not provided
79
80| Param | Type | Default | Description |
81| --- | --- | --- | --- |
82| data | <code>Object</code> | | Data that is passed to render template |
83| [options] | <code>Object</code> | <code>{}</code> | Configurable options for rendering see _RENDER for full details |
84| [options.formatRender] | <code>function</code> | <code>_RENDER</code> | Custom rendering function. It is not recommended to override the default value of this property and may no longer work properly |
85| [options.req] | <code>Object</code> | | Express request object. If options.req and options.res are defined the express .render method will be used to render template |
86| [options.res] | <code>Object</code> | | Express response object. If options.res and options.req are defined the express .render method will be used to render template |
87| [options.skip_response] | <code>Boolean</code> | | If true function will resolve with the rendered template instead of sending a response |
88| cb | <code>function</code> | | Optional callback function. If arugment is not passed function will |
89
90<a name="HTML_ADAPTER+error"></a>
91
92### htmL_ADAPTER.error(err, [options], cb) ⇒ <code>Object</code>
93Renders error view from template
94
95**Kind**: instance method of <code>[HTML_ADAPTER](#HTML_ADAPTER)</code>
96**Returns**: <code>Object</code> - Returns a Promise if cb arguement is not provided
97
98| Param | Type | Default | Description |
99| --- | --- | --- | --- |
100| err | <code>\*</code> | | Any error data that should be passed to template |
101| [options] | <code>Object</code> | <code>{}</code> | Configurable options for rendering see _ERROR for full details |
102| [options.formatError] | <code>function</code> | <code>_RENDER</code> | Custom rendering function. It is not recommended to override the default value of this property and may no longer work properly |
103| [options.req] | <code>Object</code> | | Express request object. If options.req and options.res are defined the express .render method will be used to render template |
104| [options.res] | <code>Object</code> | | Express response object. If options.res and options.req are defined the express .render method will be used to render template |
105| [options.skip_response] | <code>Boolean</code> | | If true function will resolve with the rendered |
106| cb | <code>function</code> | | Optional callback function. If arugment is not passed function will |
107
108<a name="JSON_ADAPTER"></a>
109
110## JSON_ADAPTER : <code>JSON_Adapter</code>
111Baseline adapter class which handles wrapping response data in an object with a status code and result message. Formatting is configurable both for success and error responses
112
113**Kind**: global class
114
115* [JSON_ADAPTER](#JSON_ADAPTER) : <code>JSON_Adapter</code>
116 * [new JSON_ADAPTER([options])](#new_JSON_ADAPTER_new)
117 * [.render(data, [options], [cb])](#JSON_ADAPTER+render) ⇒ <code>\*</code>
118 * [.error(err, options, [cb])](#JSON_ADAPTER+error) ⇒ <code>\*</code>
119
120<a name="new_JSON_ADAPTER_new"></a>
121
122### new JSON_ADAPTER([options])
123
124| Param | Type | Default | Description |
125| --- | --- | --- | --- |
126| [options] | <code>Object</code> | <code>{}</code> | Configurable options for the adapter |
127| options.formatRender | <code>function</code> | | Overwrites default formatting behavior for json responses |
128| options.formatError | <code>function</code> | | Overwrites default formatting behavior for errors |
129
130<a name="JSON_ADAPTER+render"></a>
131
132### jsoN_ADAPTER.render(data, [options], [cb]) ⇒ <code>\*</code>
133Creates a formatted response
134
135**Kind**: instance method of <code>[JSON_ADAPTER](#JSON_ADAPTER)</code>
136**Returns**: <code>\*</code> - Returns the formatted json object if options.sync is true or a Promise if cb arugement is not passed
137
138| Param | Type | Default | Description |
139| --- | --- | --- | --- |
140| data | <code>\*</code> | | Any data that should be sent with the success response |
141| [options] | <code>Object</code> | <code>{}</code> | Configurable options for success response formatting see _RENDER for more details |
142| [options.req] | <code>Object</code> | | Express request object. If options.req and options.res are defined the express .render method will be used to render template |
143| [options.res] | <code>Object</code> | | Express response object. If options.res and options.req are defined the express .render method will be used to render template |
144| [options.skip_response] | <code>Boolean</code> | | If true function will resolve with the rendered template instead of sending a response |
145| options.sync | <code>Boolean</code> | | If true execution of render will be handled synchronously |
146| [cb] | <code>function</code> | <code>false</code> | An optional callback function. If this argument is not a function it will be ignored |
147
148<a name="JSON_ADAPTER+error"></a>
149
150### jsoN_ADAPTER.error(err, options, [cb]) ⇒ <code>\*</code>
151Creates a formatted error response
152
153**Kind**: instance method of <code>[JSON_ADAPTER](#JSON_ADAPTER)</code>
154**Returns**: <code>\*</code> - Returns the formatted json object if options.sync is true or a Promise if cb arugement is not passed
155
156| Param | Type | Default | Description |
157| --- | --- | --- | --- |
158| err | <code>\*</code> | | Any data to be sent as part of error response |
159| options | <code>Object</code> | | Configurable options for error response formatting see _ERROR for more details |
160| options.sync | <code>Boolean</code> | | If ture execution of error will be handled synchronously |
161| [options.req] | <code>Object</code> | | Express request object. If options.req and options.res are defined the express .render method will be used to render template |
162| [options.res] | <code>Object</code> | | Express response object. If options.res and options.req are defined the express .render method will be used to render template |
163| [options.skip_response] | <code>Boolean</code> | | If true function will resolve with the rendered template instead of sending a response |
164| [cb] | <code>function</code> | <code>false</code> | An optional callback function. If this argument is not a function it will be ignored |
165
166<a name="XML_ADAPTER"></a>
167
168## XML_ADAPTER : <code>XML_Adapter</code>
169XML response adapter class which handles wrapping response data in object with status code and result message and converting into XML string.
170
171**Kind**: global class
172**Extends:** <code>JSON_Adapter</code>
173
174* [XML_ADAPTER](#XML_ADAPTER) : <code>XML_Adapter</code>
175 * [new XML_ADAPTER([options])](#new_XML_ADAPTER_new)
176 * [.render(data, [options], [cb])](#XML_ADAPTER+render) ⇒ <code>\*</code>
177 * [.error([err], [options], [cb])](#XML_ADAPTER+error) ⇒ <code>\*</code>
178
179<a name="new_XML_ADAPTER_new"></a>
180
181### new XML_ADAPTER([options])
182
183| Param | Type | Default | Description |
184| --- | --- | --- | --- |
185| [options] | <code>Object</code> | <code>{}</code> | Configurable options for XML adapter |
186| options.skip_conversion | <code>Boolean</code> | | If true render will just return data that is passed to it |
187| options.xml_root | <code>string</code> | | The value that should be used in generating the root tag of the converted XML document |
188| options.xml_configuration | <code>Object</code> | | Options that will be passed to the XML conversion function |
189
190<a name="XML_ADAPTER+render"></a>
191
192### xmL_ADAPTER.render(data, [options], [cb]) ⇒ <code>\*</code>
193Creates a formatted XML response
194
195**Kind**: instance method of <code>[XML_ADAPTER](#XML_ADAPTER)</code>
196**Returns**: <code>\*</code> - Returns the formatted XML string if options.sync is true or a Promise if cb arugement is not passed
197
198| Param | Type | Default | Description |
199| --- | --- | --- | --- |
200| data | <code>\*</code> | | Any data that should be sent with the success response |
201| [options] | <code>Object</code> | <code>{}</code> | Configurable options for the XML success response formatting see _RENDER for more details |
202| [options.formatRender] | <code>function</code> | <code>_RENDER</code> | Custom formatting function for XML rendering. It is recommended that the default value for this property is used and only custom options for the XML rendering are passed |
203| [cb] | <code>function</code> | <code>false</code> | Optional callback function. If argument is not a function it will be ignored |
204| [options.req] | <code>Object</code> | | Express request object. If options.req and options.res are defined the express .render method will be used to render template |
205| [options.res] | <code>Object</code> | | Express response object. If options.res and options.req are defined the express .render method will be used to render template |
206| [options.skip_response] | <code>Boolean</code> | | If true function will resolve with the rendered template instead of sending a response |
207
208<a name="XML_ADAPTER+error"></a>
209
210### xmL_ADAPTER.error([err], [options], [cb]) ⇒ <code>\*</code>
211Creates a formatted XML error response
212
213**Kind**: instance method of <code>[XML_ADAPTER](#XML_ADAPTER)</code>
214**Returns**: <code>\*</code> - Returns the formatted XML string if options.sync is true or a Promise if cb arugement is not passed
215
216| Param | Type | Default | Description |
217| --- | --- | --- | --- |
218| [err] | <code>\*</code> | <code>{}</code> | Any data that should be sent with the error response |
219| [options] | <code>Object</code> | <code>{}</code> | Configurable options for the XML error response formatting see _ERROR for more details |
220| [options.formatError] | <code>function</code> | <code>_ERROR</code> | Custom formatting function for XML rendering. It is recommended that the default value for this property is used and only custom options for the XML rendering are passed |
221| [options.req] | <code>Object</code> | | Express request object. If options.req and options.res are defined the express .render method will be used to render template |
222| [options.res] | <code>Object</code> | | Express response object. If options.res and options.req are defined the express .render method will be used to render template |
223| [options.skip_response] | <code>Boolean</code> | | If true function will resolve with the rendered template instead of sending a response |
224| [cb] | <code>function</code> | <code>false</code> | Optional callback function. If argument is not a function it will be ignored |
225
226<a name="CONTENT_ADAPTER_INTERFACE"></a>
227
228## CONTENT_ADAPTER_INTERFACE
229**Kind**: global class
230
231* [CONTENT_ADAPTER_INTERFACE](#CONTENT_ADAPTER_INTERFACE)
232 * [new CONTENT_ADAPTER_INTERFACE([options])](#new_CONTENT_ADAPTER_INTERFACE_new)
233 * [.create([options])](#CONTENT_ADAPTER_INTERFACE+create) ⇒ <code>Object</code>
234
235<a name="new_CONTENT_ADAPTER_INTERFACE_new"></a>
236
237### new CONTENT_ADAPTER_INTERFACE([options])
238Creates an interface
239
240
241| Param | Type | Default | Description |
242| --- | --- | --- | --- |
243| [options] | <code>Object</code> | <code>{}</code> | A set of properties defined by keys with their allowed types as values. Each property will be required by newly constructed classes from this interface |
244
245<a name="CONTENT_ADAPTER_INTERFACE+create"></a>
246
247### contenT_ADAPTER_INTERFACE.create([options]) ⇒ <code>Object</code>
248Constructs a new object with a prototype defined by the .adapter ensuring that instantiated class conforms to interface requirements
249
250**Kind**: instance method of <code>[CONTENT_ADAPTER_INTERFACE](#CONTENT_ADAPTER_INTERFACE)</code>
251**Returns**: <code>Object</code> - Returns an instantiated adapter class
252
253| Param | Type | Default | Description |
254| --- | --- | --- | --- |
255| [options] | <code>Object</code> | <code>{}</code> | Values to be passed to class constructor (.adapter should be reserved for either customer class or string that matches key in ADAPTERS) |
256| options.adapter | <code>string</code> &#124; <code>function</code> | | Required to specify type of adapter to be constructed or a class constructor that can be instantiated with new keyword |
257| options.responder | <code>string</code> &#124; <code>function</code> | | Alias for options.adapter. If options.responder is defined options.adapter will be ignored |
258
259<a name="findValidViewFromPaths"></a>
260
261## findValidViewFromPaths(_default, [dirs]) ⇒ <code>Object</code>
262Iterates through an array of file paths resolving after it finds a valid path or resolves with the default value
263
264**Kind**: global function
265**Returns**: <code>Object</code> - Returns a Promise which resolves with a file path or the default value
266
267| Param | Type | Default | Description |
268| --- | --- | --- | --- |
269| _default | <code>string</code> | | A default value to resolve if no provided file path is valid |
270| [dirs] | <code>Array.&lt;string&gt;</code> | <code>[]</code> | File paths to check for validity (file exists) |
271
272<a name="_RENDER"></a>
273
274## _RENDER(data, options, cb)
275Renders an HTML string from provided data
276
277**Kind**: global function
278
279| Param | Type | Default | Description |
280| --- | --- | --- | --- |
281| data | <code>Object</code> | | Template data should conform to EJS template by default or custom templating engine |
282| options | <code>Object</code> | | Configurable options for the rendering of HTML string |
283| [options.themename] | <code>string</code> | <code>&quot;this.themename&quot;</code> | Specifies a periodic theme folder that will be checked when looking for a matching template |
284| [options.viewname] | <code>string</code> | <code>&quot;this.viewname&quot;</code> | Specifies the filename of the template |
285| [options.extname] | <code>string</code> | <code>&quot;this.extname&quot;</code> | Specifies a periodicjs extension folder that should be checked when looking for a matching template |
286| [options.resolve_filepath] | <code>Boolean</code> | | If true a valid file path will be returned and rendering of the template file will be skipped |
287| [options.fileext] | <code>string</code> | <code>&quot;this.fileext&quot;</code> | Specifies the extension name of the template file |
288| [options.dirname] | <code>string</code> &#124; <code>Array.&lt;string&gt;</code> | | Optional custom directories to be checked for template |
289| [options.engine_configuration] | <code>Object</code> | <code>this.engine_configuration</code> | Custom configuration object for whichever templating engine being used see EJS documentation for details on options for EJS |
290| cb | <code>function</code> | | Callback function |
291
292<a name="_ERROR"></a>
293
294## _ERROR(err, options, cb)
295Renders an HTML error page template
296
297**Kind**: global function
298
299| Param | Type | Default | Description |
300| --- | --- | --- | --- |
301| err | <code>Object</code> | | If err is an instanceof Error or has a .message property only the error message will be included |
302| options | <code>Object</code> | | Configurable options for error template rendering see _RENDER for further details on options |
303| [options.viewname] | <code>string</code> | <code>&quot;\&quot;home/error404\&quot;&quot;</code> | Overrideable view name for the error template |
304| cb | <code>function</code> | | Callback function |
305
306<a name="_RENDER"></a>
307
308## _RENDER(data, options) ⇒ <code>Object</code>
309Creates a formatted success response object
310
311**Kind**: global function
312**Returns**: <code>Object</code> - Formatted success response object
313
314| Param | Type | Default | Description |
315| --- | --- | --- | --- |
316| data | <code>\*</code> | | Any data that should be sent with the success response |
317| options | <code>Object</code> | | Configurable options for success response formatting |
318| [options.formatRender] | <code>function</code> | <code>this.formatRender</code> | Custom formatting function for json success response. This argument will be ignored if not a function |
319
320<a name="_ERROR"></a>
321
322## _ERROR(err, options) ⇒ <code>Object</code>
323Creates a formatted error response object
324
325**Kind**: global function
326**Returns**: <code>Object</code> - Formatted error response object
327
328| Param | Type | Default | Description |
329| --- | --- | --- | --- |
330| err | <code>\*</code> | | Any data to be sent as part of error response |
331| options | <code>Object</code> | | Configurable options for error response formatting |
332| [options.formatError] | <code>function</code> | <code>this.formatError</code> | Custom formatting function for json error response. This argument will be ignored if not a function |
333
334<a name="_RENDER"></a>
335
336## _RENDER(data, options) ⇒ <code>string</code>
337Creates a formatted success message and converts to XML
338
339**Kind**: global function
340**Returns**: <code>string</code> - Returns the rendered XML string or the data argument if options.skip_conversion is true
341
342| Param | Type | Default | Description |
343| --- | --- | --- | --- |
344| data | <code>\*</code> | | Any data to be included in XML response |
345| options | <code>Object</code> | | Configurable options for XML response generation |
346| [options.skip_conversion] | <code>Boolean</code> | <code>this.skip_conversion</code> | If true rendering is skipped and the data argument is immediately returned |
347| [options.xml_root] | <code>string</code> | <code>&quot;this.xml_root&quot;</code> | Defines the value of the XML document root tag. If this.xml_root is not set and options.xml_root is not provided a TypeError will be thrown |
348| [options.xml_configuration] | <code>Object</code> | <code>this.xml_configuration</code> | Options for the convert function see js2xmlparser documentation for full details |
349
350<a name="_ERROR"></a>
351
352## _ERROR(err, options) ⇒ <code>string</code>
353Creates a formatted error response message and converts to XML
354
355**Kind**: global function
356**Returns**: <code>string</code> - Returns the rendered XML string or the err argument if options.skip_conversion is true
357
358| Param | Type | Default | Description |
359| --- | --- | --- | --- |
360| err | <code>\*</code> | | Error data to be included in error response. If err is an instanceof Error or has a .message property it is assumed that the .message property is the only thing to include in error response |
361| options | <code>Object</code> | | Configurable options for error XML formatting |
362| [options.skip_conversion] | <code>Boolean</code> | <code>this.skip_conversion</code> | If true rendering is skipped and the data argument is immediately returned |
363| [options.xml_root] | <code>string</code> | <code>&quot;this.xml_root&quot;</code> | Defines the value of the XML document root tag. If this.xml_root is not set and options.xml_root is not provided a TypeError will be thrown |
364| options.xml_configuration | <code>Object</code> | | Options for the convert function see js2xmlparser documentation for full details |
365