forked from StyleT/tailorx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
65 lines (57 loc) · 3.16 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/// <reference types="node" />
import { EventEmitter } from "events";
import { Stream } from "stream";
import { Url } from "url";
import { IncomingMessage, ServerResponse } from "http";
import { Span, Tracer } from 'opentracing';
export = Tailor;
declare class Tailor extends EventEmitter {
/**
* Creates new instance of Tailor
* @param options Parameters to pass to Tailor
* @param options.amdLoaderUrl URL to AMD loader. Default is RequireJS from cdnjs.
* @param options.fetchContext Function that should fetch the template, call parseTemplate and return a promise of the result. Useful to implement your own way to retrieve and cache the templates. Default implementation: serve templates from local path
* @param options.fetchTemplate Function that should fetch the template, call parseTemplate and return a promise of the result
* @param options.filterRequestHeaders Function that filters the request headers that are passed to fragment request
* @param options.filterResponseHeaders Function that maps the given response headers from the primary fragment request to the final response
* @param options.fragmentTag Name of fragment tag
* @param options.handleTags Array of custom tags.
* @param options.handleTag Receives a tag or closing tag and serializes it to a string or returns as stream
* @param options.maxAssetLinks Number of allowed link headers of CSS and JS for per fragment
* @param options.pipeAttributes Function that returns the minimal set of fragment attributes available on the frontend
* @param options.pipeInstanceName Name of pipe instance that available in the browser window object to consume frontend hooks
* @param options.requestFragment Function that returns a promise of request to a fragment server
* @param options.templatesPath Path to local templates
* @param options.tracer Opentracing compliant Tracer implementation
*/
constructor(options?: {
amdLoaderUrl?: string
, fetchContext?: (req: IncomingMessage) => Promise<object>
, fetchTemplate?: (req: IncomingMessage, parseTemplate: ParseTemplateFunction) => Promise<any>
, filterRequestHeaders?: (attributes: Attributes, req: IncomingMessage) => object
, filterResponseHeaders?: (attributes: Attributes, res: ServerResponse) => object
, fragmentTag?: string
, handledTags?: string[]
, handleTag?: (request: IncomingMessage, tag: object, options: object, context: object) => Stream | string
, maxAssetLinks?: number
, pipeAttributes?: (attributes: Attributes) => object
, pipeInstanceName?: string
, requestFragment?: (filterHeaders: (attributes: Attributes, req: IncomingMessage) => object, url: Url, attributes: Attributes, req: IncomingMessage, span?: Span) => Promise<ServerResponse>
, templatesPath?: string
, tracer?: Tracer
})
requestHandler(request: IncomingMessage, response: ServerResponse): void;
}
interface Attributes {
id: string,
src: string
async?: boolean
primary?: boolean
public?: boolean
[key: string]: any
}
type ParseTemplateFunction = (handledTags: string[], insertBeforePipeTags: string[]) => (
baseTemplate: string,
childTemplate: string,
fullRendering: boolean,
) => Promise<any>;