@tsed/platform-views 6.87.0 → 6.88.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/domain/PlatformViewsSettings.d.ts +1 -0
- package/lib/index.d.ts +0 -2
- package/lib/index.js +11 -53
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +14 -54
- package/lib/index.modern.js.map +1 -1
- package/lib/services/PlatformViews.d.ts +1 -0
- package/package.json +9 -9
- package/lib/errors/TemplateRenderError.d.ts +0 -14
- package/lib/utils/renderView.d.ts +0 -5
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var tslib = require('tslib');
|
|
|
3
3
|
var di = require('@tsed/di');
|
|
4
4
|
var Fs = require('fs');
|
|
5
5
|
var path = require('path');
|
|
6
|
-
var exceptions = require('@tsed/exceptions');
|
|
7
6
|
|
|
8
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
8
|
|
|
@@ -195,9 +194,11 @@ exports.PlatformViews = (_extensions = /*#__PURE__*/_classPrivateFieldLooseKey("
|
|
|
195
194
|
}
|
|
196
195
|
|
|
197
196
|
async $onInit() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
if (!this.disabled) {
|
|
198
|
+
_classPrivateFieldLooseBase(this, _extensions)[_extensions] = new Map(Object.entries(_extends({}, PLATFORM_VIEWS_EXTENSIONS, this.extensionsOptions)));
|
|
199
|
+
await this.loadFromConsolidate();
|
|
200
|
+
await this.loadFromTsedEngines();
|
|
201
|
+
}
|
|
201
202
|
}
|
|
202
203
|
/**
|
|
203
204
|
* @deprecated
|
|
@@ -313,63 +314,20 @@ tslib.__decorate([di.Constant("views.root", `${process.cwd()}/views`), tslib.__m
|
|
|
313
314
|
|
|
314
315
|
tslib.__decorate([di.Constant("views.cache"), tslib.__metadata("design:type", Boolean)], exports.PlatformViews.prototype, "cache", void 0);
|
|
315
316
|
|
|
317
|
+
tslib.__decorate([di.Constant("views.disabled", false), tslib.__metadata("design:type", String)], exports.PlatformViews.prototype, "disabled", void 0);
|
|
318
|
+
|
|
316
319
|
tslib.__decorate([di.Constant("views.viewEngine", "ejs"), tslib.__metadata("design:type", String)], exports.PlatformViews.prototype, "viewEngine", void 0);
|
|
317
320
|
|
|
318
321
|
tslib.__decorate([di.Constant("views.extensions", {}), tslib.__metadata("design:type", Object)], exports.PlatformViews.prototype, "extensionsOptions", void 0);
|
|
319
322
|
|
|
320
323
|
tslib.__decorate([di.Constant("views.options", {}), tslib.__metadata("design:type", Object)], exports.PlatformViews.prototype, "engineOptions", void 0);
|
|
321
324
|
|
|
322
|
-
exports.PlatformViews = tslib.__decorate([di.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
* @private
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
class TemplateRenderError extends exceptions.InternalServerError {
|
|
329
|
-
constructor(target, method, err) {
|
|
330
|
-
super(TemplateRenderError.buildMessage(target, method, err));
|
|
331
|
-
this.name = "TEMPLATE_RENDER_ERROR";
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
*
|
|
335
|
-
* @returns {string}
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
static buildMessage(target, method, err) {
|
|
340
|
-
return `Template rendering error: ${core.nameOf(target)}.${String(method)}()\n` + err;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* @ignore
|
|
347
|
-
*/
|
|
348
|
-
|
|
349
|
-
async function renderView(data, $ctx) {
|
|
350
|
-
const {
|
|
351
|
-
response,
|
|
352
|
-
endpoint
|
|
353
|
-
} = $ctx;
|
|
354
|
-
|
|
355
|
-
try {
|
|
356
|
-
const {
|
|
357
|
-
data
|
|
358
|
-
} = $ctx;
|
|
359
|
-
const {
|
|
360
|
-
path,
|
|
361
|
-
options
|
|
362
|
-
} = endpoint.view;
|
|
363
|
-
return await response.render(path, _extends({}, options, data, {
|
|
364
|
-
$ctx
|
|
365
|
-
}));
|
|
366
|
-
} catch (err) {
|
|
367
|
-
throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);
|
|
325
|
+
exports.PlatformViews = tslib.__decorate([di.Module({
|
|
326
|
+
views: {
|
|
327
|
+
exists: true
|
|
368
328
|
}
|
|
369
|
-
}
|
|
329
|
+
})], exports.PlatformViews);
|
|
370
330
|
|
|
371
331
|
exports.PLATFORM_VIEWS_EXTENSIONS = PLATFORM_VIEWS_EXTENSIONS;
|
|
372
|
-
exports.TemplateRenderError = TemplateRenderError;
|
|
373
332
|
exports.View = View;
|
|
374
|
-
exports.renderView = renderView;
|
|
375
333
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/decorators/view.ts","../src/domain/PlatformViewsSettings.ts","../src/services/PlatformViews.ts","../src/errors/TemplateRenderError.ts","../src/utils/renderView.ts"],"sourcesContent":["import {StoreSet} from \"@tsed/core\";\n\n/**\n * Use a view and sends the rendered HTML string to the client. Optional parameter:\n *\n * * viewOptions, an object whose properties define local variables for the view.\n *\n * The view argument is a string that is the file path of the view file to render.\n * This can be an absolute path, or a path relative to the views setting.\n * If the path does not contain a file extension, then the view engine setting determines the file extension.\n * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())\n * and render it using the loaded module’s __express function.\n *\n * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).\n *\n * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,\n * and as so for security reasons should not contain input from the end-user.\n *\n * @param path Relative path to the view file.\n * @param options Additional options\n * @decorator\n * @operation\n * @response\n */\nexport function View(path: string, options?: Object): MethodDecorator {\n return StoreSet(\"view\", {path, options}) as any;\n}\n","import {BaseContext} from \"@tsed/di\";\n\nexport const PLATFORM_VIEWS_EXTENSIONS = {\n atpl: \"atpl\",\n bracket: \"bracket\",\n dot: \"dot\",\n dust: \"dust\",\n ect: \"ect\",\n ejs: \"ejs\",\n haml: \"haml\",\n \"haml-coffee\": \"haml-coffee\",\n hamlet: \"hamlet\",\n hbs: \"handlebars\",\n handlebars: \"handlebars\",\n hogan: \"hogan\",\n htmling: \"htmling\",\n jazz: \"jazz\",\n jqtpl: \"jqtpl\",\n just: \"just\",\n kernel: \"kernel\",\n liquid: \"liquid\",\n liquor: \"liquor\",\n lodash: \"lodash\",\n mote: \"mote\",\n mustache: \"mustache\",\n nunjucks: \"nunjucks\",\n plates: \"plates\",\n pug: \"pug\",\n qejs: \"qejs\",\n ractive: \"ractive\",\n razor: \"razor\",\n jsx: \"react\",\n slm: \"slm\",\n squirelly: \"squirelly\",\n swig: \"swig\",\n teacup: \"teacup\",\n templayed: \"templayed\",\n toffee: \"toffee\",\n twig: \"twig\",\n underscore: \"underscore\",\n vash: \"vash\",\n velocityjs: \"velocityjs\",\n walrus: \"walrus\",\n whiskers: \"whiskers\"\n};\n\nexport type PlatformViewsExtensionsTypes = Record<string, string>;\n\nexport interface PlatformViewsEngineOptions extends Record<string, unknown> {\n requires?: any;\n}\n\nexport interface PlatformRenderOptions extends Record<string, unknown> {\n $ctx: BaseContext;\n}\n\nexport interface PlatformViewEngine {\n options: PlatformViewsEngineOptions;\n\n render(path: string, options: PlatformRenderOptions): Promise<string>;\n}\n\nexport interface PlatformViewsSettings {\n /**\n * Views directory.\n */\n root?: string;\n /**\n * Enable cache. Ts.ED enable cache in PRODUCTION profile by default.\n */\n cache?: boolean;\n /**\n * Provide extensions mapping to match the expected engines.\n */\n extensions?: Partial<PlatformViewsExtensionsTypes>;\n /**\n * Default view engine extension.\n * Allow omitting extension when using View decorator or render method.\n */\n viewEngine?: string;\n /**\n * Options mapping for each engine.\n */\n options?: Record<string, PlatformViewsEngineOptions>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n /**\n * Object to configure Views engines with Consolidate. See more on [View engine](/docs/template-engine.md).\n */\n views: PlatformViewsSettings;\n }\n }\n}\n","import {Env, getValue} from \"@tsed/core\";\nimport {Constant, Injectable} from \"@tsed/di\";\nimport Fs from \"fs\";\nimport {extname, join, resolve} from \"path\";\nimport {\n PLATFORM_VIEWS_EXTENSIONS,\n PlatformViewEngine,\n PlatformViewsEngineOptions,\n PlatformViewsExtensionsTypes\n} from \"../domain/PlatformViewsSettings\";\n\nfunction patchEJS(ejs: any) {\n return {\n compile(str: string, {client, ...options}: any) {\n return (ejs || require(\"ejs\")).compile(str, options);\n }\n };\n}\n\nasync function tryImport(name: string) {\n try {\n return await import(name);\n } catch (er) {\n // istanbul ignore next\n }\n}\n\n/**\n * @platform\n */\n@Injectable()\nexport class PlatformViews {\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"views.root\", `${process.cwd()}/views`)\n readonly root: string;\n\n @Constant(\"views.cache\")\n readonly cache: boolean;\n\n @Constant(\"views.viewEngine\", \"ejs\")\n readonly viewEngine: string;\n\n @Constant(\"views.extensions\", {})\n protected extensionsOptions: PlatformViewsExtensionsTypes;\n\n @Constant(\"views.options\", {})\n protected engineOptions: Record<string, PlatformViewsEngineOptions>;\n\n #extensions: Map<string, string>;\n #engines = new Map<string, PlatformViewEngine>();\n #cachePaths = new Map<string, {path: string; extension: string}>();\n\n async $onInit() {\n this.#extensions = new Map(\n Object.entries({\n ...PLATFORM_VIEWS_EXTENSIONS,\n ...this.extensionsOptions\n })\n );\n\n await this.loadFromConsolidate();\n await this.loadFromTsedEngines();\n }\n\n /**\n * @deprecated\n */\n async loadFromConsolidate() {\n const cons = await tryImport(\"consolidate\");\n if (cons) {\n cons.requires.ejs = patchEJS(cons.requires.ejs);\n\n this.#extensions.forEach((engineType) => {\n if ((cons as any)[engineType]) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n (cons.requires as any)[engineType] = options.requires;\n }\n\n this.registerEngine(engineType, {\n options,\n render: (cons as any)[engineType]\n });\n }\n });\n }\n }\n\n async loadFromTsedEngines() {\n const tsed = await tryImport(\"@tsed/engines\");\n\n if (tsed) {\n tsed.requires.set(\"ejs\", patchEJS(tsed.requires.get(\"ejs\")));\n\n this.#extensions.forEach((engineType) => {\n if (tsed.engines.has(engineType)) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n tsed.requires.set(engineType, options.requires);\n }\n\n this.registerEngine(engineType, {\n options,\n render: tsed.getEngine(engineType)\n });\n }\n });\n }\n }\n\n getEngines() {\n return [...this.#extensions.entries()].map(([extension, engineType]) => {\n const engine = this.getEngine(this.getExtension(engineType))!;\n\n return {\n extension,\n engine\n };\n });\n }\n\n registerEngine(engineType: string, engine: PlatformViewEngine) {\n this.#engines.set(engineType, engine);\n\n return this;\n }\n\n getEngine(type: string) {\n return this.#engines.get(this.#extensions.get(type) || type);\n }\n\n getEngineOptions(engineType: string): PlatformViewsEngineOptions {\n return getValue(this.engineOptions, engineType, {});\n }\n\n async render(viewPath: string, options: any = {}): Promise<string> {\n const {path, extension} = this.#cachePaths.get(viewPath) || this.#cachePaths.set(viewPath, this.resolve(viewPath)).get(viewPath)!;\n const engine = this.getEngine(extension);\n\n if (!engine) {\n throw new Error(`Engine not found to render the following \"${viewPath}\"`);\n }\n\n return engine.render(path, Object.assign({cache: this.cache || this.env === Env.PROD}, engine.options, options));\n }\n\n protected getExtension(viewPath: string) {\n return (extname(viewPath) || this.viewEngine).replace(/\\./, \"\");\n }\n\n protected resolve(viewPath: string) {\n const extension = this.getExtension(viewPath);\n\n viewPath = viewPath.replace(extname(viewPath), \"\") + \".\" + extension;\n\n const path =\n [\n viewPath,\n resolve(join(this.root, viewPath)),\n resolve(join(process.cwd(), \"views\", viewPath)),\n resolve(join(process.cwd(), \"public\", viewPath))\n ].find((file) => Fs.existsSync(file)) || viewPath;\n\n return {\n path,\n extension\n };\n }\n}\n","import {nameOf, Type} from \"@tsed/core\";\nimport {InternalServerError} from \"@tsed/exceptions\";\n\n/**\n * @private\n */\nexport class TemplateRenderError extends InternalServerError {\n name = \"TEMPLATE_RENDER_ERROR\";\n\n constructor(target: Type<any> | string, method: string | symbol, err: Error) {\n super(TemplateRenderError.buildMessage(target, method, err));\n }\n\n /**\n *\n * @returns {string}\n */\n static buildMessage(target: Type<any> | string, method: string | symbol, err: Error) {\n return `Template rendering error: ${nameOf(target)}.${String(method)}()\\n` + err;\n }\n}\n","import {BaseContext} from \"@tsed/di\";\nimport {TemplateRenderError} from \"../errors/TemplateRenderError\";\n\n/**\n * @ignore\n */\nexport async function renderView(data: any, $ctx: BaseContext) {\n const {response, endpoint} = $ctx;\n try {\n const {data} = $ctx;\n const {path, options} = endpoint.view;\n\n return await response.render(path, {...options, ...data, $ctx});\n } catch (err) {\n throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);\n }\n}\n"],"names":["View","path","options","StoreSet","PLATFORM_VIEWS_EXTENSIONS","atpl","bracket","dot","dust","ect","ejs","haml","hamlet","hbs","handlebars","hogan","htmling","jazz","jqtpl","just","kernel","liquid","liquor","lodash","mote","mustache","nunjucks","plates","pug","qejs","ractive","razor","jsx","slm","squirelly","swig","teacup","templayed","toffee","twig","underscore","vash","velocityjs","walrus","whiskers","patchEJS","compile","str","require","tryImport","name","er","PlatformViews","constructor","Map","$onInit","Object","entries","extensionsOptions","loadFromConsolidate","loadFromTsedEngines","cons","requires","forEach","engineType","getEngineOptions","registerEngine","render","tsed","set","get","engines","has","getEngine","getEngines","map","extension","engine","getExtension","type","getValue","engineOptions","viewPath","resolve","Error","assign","cache","env","Env","PROD","extname","viewEngine","replace","join","root","process","cwd","find","file","Fs","existsSync","__decorate","Constant","Injectable","TemplateRenderError","InternalServerError","target","method","err","buildMessage","nameOf","String","renderView","data","$ctx","response","endpoint","view","targetName","propertyKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;SAsBgBA,KAAKC,MAAcC;AACjC,SAAOC,aAAQ,CAAC,MAAD,EAAS;AA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AkB,EAAlB,sGACT;;AAjBWlD,qBAAa,qBADzBmD,aAAU,KACEnD,sBAAA;;AC5Bb;;;;MAGaoD,4BAA4BC;AAGvCpD,EAAAA,YAAYqD,QAA4BC,QAAyBC;AAC/D,UAAMJ,mBAAmB,CAACK,YAApB,CAAiCH,MAAjC,EAAyCC,MAAzC,EAAiDC,GAAjD,CAAN;AAHF,aAAA,GAAO,uBAAP;AAIC;AAED;;;;;;AAImB,SAAZC,YAAY,CAACH,MAAD,EAA6BC,MAA7B,EAAsDC,GAAtD;AACjB,wCAAoCE,WAAM,CAACJ,MAAD,KAAYK,MAAM,CAACJ,MAAD,OAArD,GAAsEC,GAA7E;AACD;;;;AChBH;;;;AAGO,eAAeI,UAAf,CAA0BC,IAA1B,EAAqCC,IAArC;AACL,QAAM;AAACC,IAAAA,QAAD;AAAWC,IAAAA;AAAX,MAAuBF,IAA7B;;AACA,MAAI;AACF,UAAM;AAACD,MAAAA;AAAD,QAASC,IAAf;AACA,UAAM;AAACjH,MAAAA,IAAD;AAAOC,MAAAA;AAAP,QAAkBkH,QAAQ,CAACC,IAAjC;AAEA,WAAO,MAAMF,QAAQ,CAAChD,MAAT,CAAgBlE,IAAhB,eAA0BC,OAA1B,EAAsC+G,IAAtC;AAA4CC,MAAAA;AAA5C,OAAb;AACD,GALD,CAKE,OAAON,GAAP,EAAY;AACZ,UAAM,IAAIJ,mBAAJ,CAAwBY,QAAQ,CAACE,UAAjC,EAA6CF,QAAQ,CAACG,WAAtD,EAAmEX,GAAnE,CAAN;AACD;AACF;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/decorators/view.ts","../src/domain/PlatformViewsSettings.ts","../src/services/PlatformViews.ts"],"sourcesContent":["import {StoreSet} from \"@tsed/core\";\n\n/**\n * Use a view and sends the rendered HTML string to the client. Optional parameter:\n *\n * * viewOptions, an object whose properties define local variables for the view.\n *\n * The view argument is a string that is the file path of the view file to render.\n * This can be an absolute path, or a path relative to the views setting.\n * If the path does not contain a file extension, then the view engine setting determines the file extension.\n * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())\n * and render it using the loaded module’s __express function.\n *\n * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).\n *\n * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,\n * and as so for security reasons should not contain input from the end-user.\n *\n * @param path Relative path to the view file.\n * @param options Additional options\n * @decorator\n * @operation\n * @response\n */\nexport function View(path: string, options?: Object): MethodDecorator {\n return StoreSet(\"view\", {path, options}) as any;\n}\n","import {BaseContext} from \"@tsed/di\";\n\nexport const PLATFORM_VIEWS_EXTENSIONS = {\n atpl: \"atpl\",\n bracket: \"bracket\",\n dot: \"dot\",\n dust: \"dust\",\n ect: \"ect\",\n ejs: \"ejs\",\n haml: \"haml\",\n \"haml-coffee\": \"haml-coffee\",\n hamlet: \"hamlet\",\n hbs: \"handlebars\",\n handlebars: \"handlebars\",\n hogan: \"hogan\",\n htmling: \"htmling\",\n jazz: \"jazz\",\n jqtpl: \"jqtpl\",\n just: \"just\",\n kernel: \"kernel\",\n liquid: \"liquid\",\n liquor: \"liquor\",\n lodash: \"lodash\",\n mote: \"mote\",\n mustache: \"mustache\",\n nunjucks: \"nunjucks\",\n plates: \"plates\",\n pug: \"pug\",\n qejs: \"qejs\",\n ractive: \"ractive\",\n razor: \"razor\",\n jsx: \"react\",\n slm: \"slm\",\n squirelly: \"squirelly\",\n swig: \"swig\",\n teacup: \"teacup\",\n templayed: \"templayed\",\n toffee: \"toffee\",\n twig: \"twig\",\n underscore: \"underscore\",\n vash: \"vash\",\n velocityjs: \"velocityjs\",\n walrus: \"walrus\",\n whiskers: \"whiskers\"\n};\n\nexport type PlatformViewsExtensionsTypes = Record<string, string>;\n\nexport interface PlatformViewsEngineOptions extends Record<string, unknown> {\n requires?: any;\n}\n\nexport interface PlatformRenderOptions extends Record<string, unknown> {\n $ctx: BaseContext;\n}\n\nexport interface PlatformViewEngine {\n options: PlatformViewsEngineOptions;\n\n render(path: string, options: PlatformRenderOptions): Promise<string>;\n}\n\nexport interface PlatformViewsSettings {\n disabled?: boolean;\n /**\n * Views directory.\n */\n root?: string;\n /**\n * Enable cache. Ts.ED enable cache in PRODUCTION profile by default.\n */\n cache?: boolean;\n /**\n * Provide extensions mapping to match the expected engines.\n */\n extensions?: Partial<PlatformViewsExtensionsTypes>;\n /**\n * Default view engine extension.\n * Allow omitting extension when using View decorator or render method.\n */\n viewEngine?: string;\n /**\n * Options mapping for each engine.\n */\n options?: Record<string, PlatformViewsEngineOptions>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n /**\n * Object to configure Views engines with Consolidate. See more on [View engine](/docs/template-engine.md).\n */\n views: PlatformViewsSettings;\n }\n }\n}\n","import {Env, getValue} from \"@tsed/core\";\nimport {Constant, Module} from \"@tsed/di\";\nimport Fs from \"fs\";\nimport {extname, join, resolve} from \"path\";\nimport {\n PLATFORM_VIEWS_EXTENSIONS,\n PlatformViewEngine,\n PlatformViewsEngineOptions,\n PlatformViewsExtensionsTypes\n} from \"../domain/PlatformViewsSettings\";\n\nfunction patchEJS(ejs: any) {\n return {\n compile(str: string, {client, ...options}: any) {\n return (ejs || require(\"ejs\")).compile(str, options);\n }\n };\n}\n\nasync function tryImport(name: string) {\n try {\n return await import(name);\n } catch (er) {\n // istanbul ignore next\n }\n}\n\n/**\n * @platform\n */\n@Module({\n views: {\n exists: true\n }\n})\nexport class PlatformViews {\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"views.root\", `${process.cwd()}/views`)\n readonly root: string;\n\n @Constant(\"views.cache\")\n readonly cache: boolean;\n\n @Constant(\"views.disabled\", false)\n readonly disabled: string;\n\n @Constant(\"views.viewEngine\", \"ejs\")\n readonly viewEngine: string;\n\n @Constant(\"views.extensions\", {})\n protected extensionsOptions: PlatformViewsExtensionsTypes;\n\n @Constant(\"views.options\", {})\n protected engineOptions: Record<string, PlatformViewsEngineOptions>;\n\n #extensions: Map<string, string>;\n #engines = new Map<string, PlatformViewEngine>();\n #cachePaths = new Map<string, {path: string; extension: string}>();\n\n async $onInit() {\n if (!this.disabled) {\n this.#extensions = new Map(\n Object.entries({\n ...PLATFORM_VIEWS_EXTENSIONS,\n ...this.extensionsOptions\n })\n );\n\n await this.loadFromConsolidate();\n await this.loadFromTsedEngines();\n }\n }\n\n /**\n * @deprecated\n */\n async loadFromConsolidate() {\n const cons = await tryImport(\"consolidate\");\n if (cons) {\n cons.requires.ejs = patchEJS(cons.requires.ejs);\n\n this.#extensions.forEach((engineType) => {\n if ((cons as any)[engineType]) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n (cons.requires as any)[engineType] = options.requires;\n }\n\n this.registerEngine(engineType, {\n options,\n render: (cons as any)[engineType]\n });\n }\n });\n }\n }\n\n async loadFromTsedEngines() {\n const tsed = await tryImport(\"@tsed/engines\");\n\n if (tsed) {\n tsed.requires.set(\"ejs\", patchEJS(tsed.requires.get(\"ejs\")));\n\n this.#extensions.forEach((engineType) => {\n if (tsed.engines.has(engineType)) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n tsed.requires.set(engineType, options.requires);\n }\n\n this.registerEngine(engineType, {\n options,\n render: tsed.getEngine(engineType)\n });\n }\n });\n }\n }\n\n getEngines() {\n return [...this.#extensions.entries()].map(([extension, engineType]) => {\n const engine = this.getEngine(this.getExtension(engineType))!;\n\n return {\n extension,\n engine\n };\n });\n }\n\n registerEngine(engineType: string, engine: PlatformViewEngine) {\n this.#engines.set(engineType, engine);\n\n return this;\n }\n\n getEngine(type: string) {\n return this.#engines.get(this.#extensions.get(type) || type);\n }\n\n getEngineOptions(engineType: string): PlatformViewsEngineOptions {\n return getValue(this.engineOptions, engineType, {});\n }\n\n async render(viewPath: string, options: any = {}): Promise<string> {\n const {path, extension} = this.#cachePaths.get(viewPath) || this.#cachePaths.set(viewPath, this.resolve(viewPath)).get(viewPath)!;\n const engine = this.getEngine(extension);\n\n if (!engine) {\n throw new Error(`Engine not found to render the following \"${viewPath}\"`);\n }\n\n return engine.render(path, Object.assign({cache: this.cache || this.env === Env.PROD}, engine.options, options));\n }\n\n protected getExtension(viewPath: string) {\n return (extname(viewPath) || this.viewEngine).replace(/\\./, \"\");\n }\n\n protected resolve(viewPath: string) {\n const extension = this.getExtension(viewPath);\n\n viewPath = viewPath.replace(extname(viewPath), \"\") + \".\" + extension;\n\n const path =\n [\n viewPath,\n resolve(join(this.root, viewPath)),\n resolve(join(process.cwd(), \"views\", viewPath)),\n resolve(join(process.cwd(), \"public\", viewPath))\n ].find((file) => Fs.existsSync(file)) || viewPath;\n\n return {\n path,\n extension\n };\n }\n}\n"],"names":["View","path","options","StoreSet","PLATFORM_VIEWS_EXTENSIONS","atpl","bracket","dot","dust","ect","ejs","haml","hamlet","hbs","handlebars","hogan","htmling","jazz","jqtpl","just","kernel","liquid","liquor","lodash","mote","mustache","nunjucks","plates","pug","qejs","ractive","razor","jsx","slm","squirelly","swig","teacup","templayed","toffee","twig","underscore","vash","velocityjs","walrus","whiskers","patchEJS","compile","str","require","tryImport","name","er","PlatformViews","constructor","Map","$onInit","disabled","Object","entries","extensionsOptions","loadFromConsolidate","loadFromTsedEngines","cons","requires","forEach","engineType","getEngineOptions","registerEngine","render","tsed","set","get","engines","has","getEngine","getEngines","map","extension","engine","getExtension","type","getValue","engineOptions","viewPath","resolve","Error","assign","cache","env","Env","PROD","extname","viewEngine","replace","join","root","process","cwd","find","file","Fs","existsSync","__decorate","Constant","Module","views","exists"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;SAsBgBA,KAAKC,MAAcC;AACjC,SAAOC,aAAQ,CAAC,MAAD,EAAS;AAACF,IAAAA,IAAD;AAAOC,IAAAA;AAAP,GAAT,CAAf;AACD;;MCxBYE,yBAAyB,GAAG;AACvCC,EAAAA,IAAI,EAAE,MADiC;AAEvCC,EAAAA,OAAO,EAAE,SAF8B;AAGvCC,EAAAA,GAAG,EAAE,KAHkC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AAE;AACLC,IAAAA,MAAM,EAAE;AADH;AADD,CAAD,IAKMtD,sBAAA;;;;;"}
|
package/lib/index.modern.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { StoreSet, getValue, Env
|
|
1
|
+
import { StoreSet, getValue, Env } from '@tsed/core';
|
|
2
2
|
import { __decorate, __metadata } from 'tslib';
|
|
3
|
-
import { Constant,
|
|
3
|
+
import { Constant, Module } from '@tsed/di';
|
|
4
4
|
import Fs from 'fs';
|
|
5
5
|
import { extname, resolve, join } from 'path';
|
|
6
|
-
import { InternalServerError } from '@tsed/exceptions';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
@@ -171,9 +170,11 @@ let PlatformViews = (_extensions = /*#__PURE__*/_classPrivateFieldLooseKey("exte
|
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
async $onInit() {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
if (!this.disabled) {
|
|
174
|
+
_classPrivateFieldLooseBase(this, _extensions)[_extensions] = new Map(Object.entries(_extends({}, PLATFORM_VIEWS_EXTENSIONS, this.extensionsOptions)));
|
|
175
|
+
await this.loadFromConsolidate();
|
|
176
|
+
await this.loadFromTsedEngines();
|
|
177
|
+
}
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
180
|
* @deprecated
|
|
@@ -289,60 +290,19 @@ __decorate([Constant("views.root", `${process.cwd()}/views`), __metadata("design
|
|
|
289
290
|
|
|
290
291
|
__decorate([Constant("views.cache"), __metadata("design:type", Boolean)], PlatformViews.prototype, "cache", void 0);
|
|
291
292
|
|
|
293
|
+
__decorate([Constant("views.disabled", false), __metadata("design:type", String)], PlatformViews.prototype, "disabled", void 0);
|
|
294
|
+
|
|
292
295
|
__decorate([Constant("views.viewEngine", "ejs"), __metadata("design:type", String)], PlatformViews.prototype, "viewEngine", void 0);
|
|
293
296
|
|
|
294
297
|
__decorate([Constant("views.extensions", {}), __metadata("design:type", Object)], PlatformViews.prototype, "extensionsOptions", void 0);
|
|
295
298
|
|
|
296
299
|
__decorate([Constant("views.options", {}), __metadata("design:type", Object)], PlatformViews.prototype, "engineOptions", void 0);
|
|
297
300
|
|
|
298
|
-
PlatformViews = __decorate([
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
class TemplateRenderError extends InternalServerError {
|
|
305
|
-
constructor(target, method, err) {
|
|
306
|
-
super(TemplateRenderError.buildMessage(target, method, err));
|
|
307
|
-
this.name = "TEMPLATE_RENDER_ERROR";
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
*
|
|
311
|
-
* @returns {string}
|
|
312
|
-
*/
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
static buildMessage(target, method, err) {
|
|
316
|
-
return `Template rendering error: ${nameOf(target)}.${String(method)}()\n` + err;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* @ignore
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
async function renderView(data, $ctx) {
|
|
326
|
-
const {
|
|
327
|
-
response,
|
|
328
|
-
endpoint
|
|
329
|
-
} = $ctx;
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
const {
|
|
333
|
-
data: _data
|
|
334
|
-
} = $ctx;
|
|
335
|
-
const {
|
|
336
|
-
path,
|
|
337
|
-
options
|
|
338
|
-
} = endpoint.view;
|
|
339
|
-
return await response.render(path, _extends({}, options, _data, {
|
|
340
|
-
$ctx
|
|
341
|
-
}));
|
|
342
|
-
} catch (err) {
|
|
343
|
-
throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);
|
|
301
|
+
PlatformViews = __decorate([Module({
|
|
302
|
+
views: {
|
|
303
|
+
exists: true
|
|
344
304
|
}
|
|
345
|
-
}
|
|
305
|
+
})], PlatformViews);
|
|
346
306
|
|
|
347
|
-
export { PLATFORM_VIEWS_EXTENSIONS, PlatformViews,
|
|
307
|
+
export { PLATFORM_VIEWS_EXTENSIONS, PlatformViews, View };
|
|
348
308
|
//# sourceMappingURL=index.modern.js.map
|
package/lib/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/decorators/view.ts","../src/domain/PlatformViewsSettings.ts","../src/services/PlatformViews.ts","../src/errors/TemplateRenderError.ts","../src/utils/renderView.ts"],"sourcesContent":["import {StoreSet} from \"@tsed/core\";\n\n/**\n * Use a view and sends the rendered HTML string to the client. Optional parameter:\n *\n * * viewOptions, an object whose properties define local variables for the view.\n *\n * The view argument is a string that is the file path of the view file to render.\n * This can be an absolute path, or a path relative to the views setting.\n * If the path does not contain a file extension, then the view engine setting determines the file extension.\n * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())\n * and render it using the loaded module’s __express function.\n *\n * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).\n *\n * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,\n * and as so for security reasons should not contain input from the end-user.\n *\n * @param path Relative path to the view file.\n * @param options Additional options\n * @decorator\n * @operation\n * @response\n */\nexport function View(path: string, options?: Object): MethodDecorator {\n return StoreSet(\"view\", {path, options}) as any;\n}\n","import {BaseContext} from \"@tsed/di\";\n\nexport const PLATFORM_VIEWS_EXTENSIONS = {\n atpl: \"atpl\",\n bracket: \"bracket\",\n dot: \"dot\",\n dust: \"dust\",\n ect: \"ect\",\n ejs: \"ejs\",\n haml: \"haml\",\n \"haml-coffee\": \"haml-coffee\",\n hamlet: \"hamlet\",\n hbs: \"handlebars\",\n handlebars: \"handlebars\",\n hogan: \"hogan\",\n htmling: \"htmling\",\n jazz: \"jazz\",\n jqtpl: \"jqtpl\",\n just: \"just\",\n kernel: \"kernel\",\n liquid: \"liquid\",\n liquor: \"liquor\",\n lodash: \"lodash\",\n mote: \"mote\",\n mustache: \"mustache\",\n nunjucks: \"nunjucks\",\n plates: \"plates\",\n pug: \"pug\",\n qejs: \"qejs\",\n ractive: \"ractive\",\n razor: \"razor\",\n jsx: \"react\",\n slm: \"slm\",\n squirelly: \"squirelly\",\n swig: \"swig\",\n teacup: \"teacup\",\n templayed: \"templayed\",\n toffee: \"toffee\",\n twig: \"twig\",\n underscore: \"underscore\",\n vash: \"vash\",\n velocityjs: \"velocityjs\",\n walrus: \"walrus\",\n whiskers: \"whiskers\"\n};\n\nexport type PlatformViewsExtensionsTypes = Record<string, string>;\n\nexport interface PlatformViewsEngineOptions extends Record<string, unknown> {\n requires?: any;\n}\n\nexport interface PlatformRenderOptions extends Record<string, unknown> {\n $ctx: BaseContext;\n}\n\nexport interface PlatformViewEngine {\n options: PlatformViewsEngineOptions;\n\n render(path: string, options: PlatformRenderOptions): Promise<string>;\n}\n\nexport interface PlatformViewsSettings {\n /**\n * Views directory.\n */\n root?: string;\n /**\n * Enable cache. Ts.ED enable cache in PRODUCTION profile by default.\n */\n cache?: boolean;\n /**\n * Provide extensions mapping to match the expected engines.\n */\n extensions?: Partial<PlatformViewsExtensionsTypes>;\n /**\n * Default view engine extension.\n * Allow omitting extension when using View decorator or render method.\n */\n viewEngine?: string;\n /**\n * Options mapping for each engine.\n */\n options?: Record<string, PlatformViewsEngineOptions>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n /**\n * Object to configure Views engines with Consolidate. See more on [View engine](/docs/template-engine.md).\n */\n views: PlatformViewsSettings;\n }\n }\n}\n","import {Env, getValue} from \"@tsed/core\";\nimport {Constant, Injectable} from \"@tsed/di\";\nimport Fs from \"fs\";\nimport {extname, join, resolve} from \"path\";\nimport {\n PLATFORM_VIEWS_EXTENSIONS,\n PlatformViewEngine,\n PlatformViewsEngineOptions,\n PlatformViewsExtensionsTypes\n} from \"../domain/PlatformViewsSettings\";\n\nfunction patchEJS(ejs: any) {\n return {\n compile(str: string, {client, ...options}: any) {\n return (ejs || require(\"ejs\")).compile(str, options);\n }\n };\n}\n\nasync function tryImport(name: string) {\n try {\n return await import(name);\n } catch (er) {\n // istanbul ignore next\n }\n}\n\n/**\n * @platform\n */\n@Injectable()\nexport class PlatformViews {\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"views.root\", `${process.cwd()}/views`)\n readonly root: string;\n\n @Constant(\"views.cache\")\n readonly cache: boolean;\n\n @Constant(\"views.viewEngine\", \"ejs\")\n readonly viewEngine: string;\n\n @Constant(\"views.extensions\", {})\n protected extensionsOptions: PlatformViewsExtensionsTypes;\n\n @Constant(\"views.options\", {})\n protected engineOptions: Record<string, PlatformViewsEngineOptions>;\n\n #extensions: Map<string, string>;\n #engines = new Map<string, PlatformViewEngine>();\n #cachePaths = new Map<string, {path: string; extension: string}>();\n\n async $onInit() {\n this.#extensions = new Map(\n Object.entries({\n ...PLATFORM_VIEWS_EXTENSIONS,\n ...this.extensionsOptions\n })\n );\n\n await this.loadFromConsolidate();\n await this.loadFromTsedEngines();\n }\n\n /**\n * @deprecated\n */\n async loadFromConsolidate() {\n const cons = await tryImport(\"consolidate\");\n if (cons) {\n cons.requires.ejs = patchEJS(cons.requires.ejs);\n\n this.#extensions.forEach((engineType) => {\n if ((cons as any)[engineType]) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n (cons.requires as any)[engineType] = options.requires;\n }\n\n this.registerEngine(engineType, {\n options,\n render: (cons as any)[engineType]\n });\n }\n });\n }\n }\n\n async loadFromTsedEngines() {\n const tsed = await tryImport(\"@tsed/engines\");\n\n if (tsed) {\n tsed.requires.set(\"ejs\", patchEJS(tsed.requires.get(\"ejs\")));\n\n this.#extensions.forEach((engineType) => {\n if (tsed.engines.has(engineType)) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n tsed.requires.set(engineType, options.requires);\n }\n\n this.registerEngine(engineType, {\n options,\n render: tsed.getEngine(engineType)\n });\n }\n });\n }\n }\n\n getEngines() {\n return [...this.#extensions.entries()].map(([extension, engineType]) => {\n const engine = this.getEngine(this.getExtension(engineType))!;\n\n return {\n extension,\n engine\n };\n });\n }\n\n registerEngine(engineType: string, engine: PlatformViewEngine) {\n this.#engines.set(engineType, engine);\n\n return this;\n }\n\n getEngine(type: string) {\n return this.#engines.get(this.#extensions.get(type) || type);\n }\n\n getEngineOptions(engineType: string): PlatformViewsEngineOptions {\n return getValue(this.engineOptions, engineType, {});\n }\n\n async render(viewPath: string, options: any = {}): Promise<string> {\n const {path, extension} = this.#cachePaths.get(viewPath) || this.#cachePaths.set(viewPath, this.resolve(viewPath)).get(viewPath)!;\n const engine = this.getEngine(extension);\n\n if (!engine) {\n throw new Error(`Engine not found to render the following \"${viewPath}\"`);\n }\n\n return engine.render(path, Object.assign({cache: this.cache || this.env === Env.PROD}, engine.options, options));\n }\n\n protected getExtension(viewPath: string) {\n return (extname(viewPath) || this.viewEngine).replace(/\\./, \"\");\n }\n\n protected resolve(viewPath: string) {\n const extension = this.getExtension(viewPath);\n\n viewPath = viewPath.replace(extname(viewPath), \"\") + \".\" + extension;\n\n const path =\n [\n viewPath,\n resolve(join(this.root, viewPath)),\n resolve(join(process.cwd(), \"views\", viewPath)),\n resolve(join(process.cwd(), \"public\", viewPath))\n ].find((file) => Fs.existsSync(file)) || viewPath;\n\n return {\n path,\n extension\n };\n }\n}\n","import {nameOf, Type} from \"@tsed/core\";\nimport {InternalServerError} from \"@tsed/exceptions\";\n\n/**\n * @private\n */\nexport class TemplateRenderError extends InternalServerError {\n name = \"TEMPLATE_RENDER_ERROR\";\n\n constructor(target: Type<any> | string, method: string | symbol, err: Error) {\n super(TemplateRenderError.buildMessage(target, method, err));\n }\n\n /**\n *\n * @returns {string}\n */\n static buildMessage(target: Type<any> | string, method: string | symbol, err: Error) {\n return `Template rendering error: ${nameOf(target)}.${String(method)}()\\n` + err;\n }\n}\n","import {BaseContext} from \"@tsed/di\";\nimport {TemplateRenderError} from \"../errors/TemplateRenderError\";\n\n/**\n * @ignore\n */\nexport async function renderView(data: any, $ctx: BaseContext) {\n const {response, endpoint} = $ctx;\n try {\n const {data} = $ctx;\n const {path, options} = endpoint.view;\n\n return await response.render(path, {...options, ...data, $ctx});\n } catch (err) {\n throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);\n }\n}\n"],"names":["View","path","options","StoreSet","PLATFORM_VIEWS_EXTENSIONS","atpl","bracket","dot","dust","ect","ejs","haml","hamlet","hbs","handlebars","hogan","htmling","jazz","jqtpl","just","kernel","liquid","liquor","lodash","mote","mustache","nunjucks","plates","pug","qejs","ractive","razor","jsx","slm","squirelly","swig","teacup","templayed","toffee","twig","underscore","vash","velocityjs","walrus","whiskers","patchEJS","compile","str","require","tryImport","name","er","PlatformViews","constructor","Map","$onInit","Object","entries","extensionsOptions","loadFromConsolidate","loadFromTsedEngines","cons","requires","forEach","engineType","getEngineOptions","registerEngine","render","tsed","set","get","engines","has","getEngine","getEngines","map","extension","engine","getExtension","type","getValue","engineOptions","viewPath","resolve","Error","assign","cache","env","Env","PROD","extname","viewEngine","replace","join","root","process","cwd","find","file","Fs","existsSync","__decorate","Constant","Injectable","TemplateRenderError","InternalServerError","target","method","err","buildMessage","nameOf","String","renderView","data","$ctx","response","endpoint","view","targetName","propertyKey"],"mappings":";;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;SAsBgBA,KAAKC,MAAcC;AACjC,SAAOC,QAAQ,CAAC,MAAD,EAAS;AAACF,IAAAA,IAAD;AAAOC,IAAAA;AAAP,GAAT,CAAf;AACD;;MCxBYE,yBAAyB,GAAG;AACvCC,EAAAA,IAAI,EAAE,MADiC;AAEvCC,EAAAA,OAAO,EAAE,SAF8B;AAGvCC,EAAAA,GAAG,EAAE,KAHkC;AAIvCC,EAAAA,IAAI,EAAE,MAJiC;AAKvCC,EAAAA,GAAG,EAAE,KALkC;AAMvCC,EAAAA,GAAG,EAAE,KANkC;AAOvCC,EAAAA,IAAI,EAAE,MAPiC;AAQvC,iBAAe,aARwB;AASvCC,EAAAA,MAAM,EAAE,QAT+B;AAUv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AD,OAArD,GAAsEC,GAA7E;AACD;;;;AChBH;;;;AAGO,eAAeI,UAAf,CAA0BC,IAA1B,EAAqCC,IAArC;AACL,QAAM;AAACC,IAAAA,QAAD;AAAWC,IAAAA;AAAX,MAAuBF,IAA7B;;AACA,MAAI;AACF,UAAM;AAACD,MAAAA,IAAI,EAAJA;AAAD,QAASC,IAAf;AACA,UAAM;AAACjH,MAAAA,IAAD;AAAOC,MAAAA;AAAP,QAAkBkH,QAAQ,CAACC,IAAjC;AAEA,WAAO,MAAMF,QAAQ,CAAChD,MAAT,CAAgBlE,IAAhB,eAA0BC,OAA1B,EAAsC+G,KAAtC;AAA4CC,MAAAA;AAA5C,OAAb;AACD,GALD,CAKE,OAAON,GAAP,EAAY;AACZ,UAAM,IAAIJ,mBAAJ,CAAwBY,QAAQ,CAACE,UAAjC,EAA6CF,QAAQ,CAACG,WAAtD,EAAmEX,GAAnE,CAAN;AACD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/decorators/view.ts","../src/domain/PlatformViewsSettings.ts","../src/services/PlatformViews.ts"],"sourcesContent":["import {StoreSet} from \"@tsed/core\";\n\n/**\n * Use a view and sends the rendered HTML string to the client. Optional parameter:\n *\n * * viewOptions, an object whose properties define local variables for the view.\n *\n * The view argument is a string that is the file path of the view file to render.\n * This can be an absolute path, or a path relative to the views setting.\n * If the path does not contain a file extension, then the view engine setting determines the file extension.\n * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())\n * and render it using the loaded module’s __express function.\n *\n * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).\n *\n * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,\n * and as so for security reasons should not contain input from the end-user.\n *\n * @param path Relative path to the view file.\n * @param options Additional options\n * @decorator\n * @operation\n * @response\n */\nexport function View(path: string, options?: Object): MethodDecorator {\n return StoreSet(\"view\", {path, options}) as any;\n}\n","import {BaseContext} from \"@tsed/di\";\n\nexport const PLATFORM_VIEWS_EXTENSIONS = {\n atpl: \"atpl\",\n bracket: \"bracket\",\n dot: \"dot\",\n dust: \"dust\",\n ect: \"ect\",\n ejs: \"ejs\",\n haml: \"haml\",\n \"haml-coffee\": \"haml-coffee\",\n hamlet: \"hamlet\",\n hbs: \"handlebars\",\n handlebars: \"handlebars\",\n hogan: \"hogan\",\n htmling: \"htmling\",\n jazz: \"jazz\",\n jqtpl: \"jqtpl\",\n just: \"just\",\n kernel: \"kernel\",\n liquid: \"liquid\",\n liquor: \"liquor\",\n lodash: \"lodash\",\n mote: \"mote\",\n mustache: \"mustache\",\n nunjucks: \"nunjucks\",\n plates: \"plates\",\n pug: \"pug\",\n qejs: \"qejs\",\n ractive: \"ractive\",\n razor: \"razor\",\n jsx: \"react\",\n slm: \"slm\",\n squirelly: \"squirelly\",\n swig: \"swig\",\n teacup: \"teacup\",\n templayed: \"templayed\",\n toffee: \"toffee\",\n twig: \"twig\",\n underscore: \"underscore\",\n vash: \"vash\",\n velocityjs: \"velocityjs\",\n walrus: \"walrus\",\n whiskers: \"whiskers\"\n};\n\nexport type PlatformViewsExtensionsTypes = Record<string, string>;\n\nexport interface PlatformViewsEngineOptions extends Record<string, unknown> {\n requires?: any;\n}\n\nexport interface PlatformRenderOptions extends Record<string, unknown> {\n $ctx: BaseContext;\n}\n\nexport interface PlatformViewEngine {\n options: PlatformViewsEngineOptions;\n\n render(path: string, options: PlatformRenderOptions): Promise<string>;\n}\n\nexport interface PlatformViewsSettings {\n disabled?: boolean;\n /**\n * Views directory.\n */\n root?: string;\n /**\n * Enable cache. Ts.ED enable cache in PRODUCTION profile by default.\n */\n cache?: boolean;\n /**\n * Provide extensions mapping to match the expected engines.\n */\n extensions?: Partial<PlatformViewsExtensionsTypes>;\n /**\n * Default view engine extension.\n * Allow omitting extension when using View decorator or render method.\n */\n viewEngine?: string;\n /**\n * Options mapping for each engine.\n */\n options?: Record<string, PlatformViewsEngineOptions>;\n}\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n /**\n * Object to configure Views engines with Consolidate. See more on [View engine](/docs/template-engine.md).\n */\n views: PlatformViewsSettings;\n }\n }\n}\n","import {Env, getValue} from \"@tsed/core\";\nimport {Constant, Module} from \"@tsed/di\";\nimport Fs from \"fs\";\nimport {extname, join, resolve} from \"path\";\nimport {\n PLATFORM_VIEWS_EXTENSIONS,\n PlatformViewEngine,\n PlatformViewsEngineOptions,\n PlatformViewsExtensionsTypes\n} from \"../domain/PlatformViewsSettings\";\n\nfunction patchEJS(ejs: any) {\n return {\n compile(str: string, {client, ...options}: any) {\n return (ejs || require(\"ejs\")).compile(str, options);\n }\n };\n}\n\nasync function tryImport(name: string) {\n try {\n return await import(name);\n } catch (er) {\n // istanbul ignore next\n }\n}\n\n/**\n * @platform\n */\n@Module({\n views: {\n exists: true\n }\n})\nexport class PlatformViews {\n @Constant(\"env\")\n env: Env;\n\n @Constant(\"views.root\", `${process.cwd()}/views`)\n readonly root: string;\n\n @Constant(\"views.cache\")\n readonly cache: boolean;\n\n @Constant(\"views.disabled\", false)\n readonly disabled: string;\n\n @Constant(\"views.viewEngine\", \"ejs\")\n readonly viewEngine: string;\n\n @Constant(\"views.extensions\", {})\n protected extensionsOptions: PlatformViewsExtensionsTypes;\n\n @Constant(\"views.options\", {})\n protected engineOptions: Record<string, PlatformViewsEngineOptions>;\n\n #extensions: Map<string, string>;\n #engines = new Map<string, PlatformViewEngine>();\n #cachePaths = new Map<string, {path: string; extension: string}>();\n\n async $onInit() {\n if (!this.disabled) {\n this.#extensions = new Map(\n Object.entries({\n ...PLATFORM_VIEWS_EXTENSIONS,\n ...this.extensionsOptions\n })\n );\n\n await this.loadFromConsolidate();\n await this.loadFromTsedEngines();\n }\n }\n\n /**\n * @deprecated\n */\n async loadFromConsolidate() {\n const cons = await tryImport(\"consolidate\");\n if (cons) {\n cons.requires.ejs = patchEJS(cons.requires.ejs);\n\n this.#extensions.forEach((engineType) => {\n if ((cons as any)[engineType]) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n (cons.requires as any)[engineType] = options.requires;\n }\n\n this.registerEngine(engineType, {\n options,\n render: (cons as any)[engineType]\n });\n }\n });\n }\n }\n\n async loadFromTsedEngines() {\n const tsed = await tryImport(\"@tsed/engines\");\n\n if (tsed) {\n tsed.requires.set(\"ejs\", patchEJS(tsed.requires.get(\"ejs\")));\n\n this.#extensions.forEach((engineType) => {\n if (tsed.engines.has(engineType)) {\n const options = this.getEngineOptions(engineType);\n\n if (options.requires) {\n tsed.requires.set(engineType, options.requires);\n }\n\n this.registerEngine(engineType, {\n options,\n render: tsed.getEngine(engineType)\n });\n }\n });\n }\n }\n\n getEngines() {\n return [...this.#extensions.entries()].map(([extension, engineType]) => {\n const engine = this.getEngine(this.getExtension(engineType))!;\n\n return {\n extension,\n engine\n };\n });\n }\n\n registerEngine(engineType: string, engine: PlatformViewEngine) {\n this.#engines.set(engineType, engine);\n\n return this;\n }\n\n getEngine(type: string) {\n return this.#engines.get(this.#extensions.get(type) || type);\n }\n\n getEngineOptions(engineType: string): PlatformViewsEngineOptions {\n return getValue(this.engineOptions, engineType, {});\n }\n\n async render(viewPath: string, options: any = {}): Promise<string> {\n const {path, extension} = this.#cachePaths.get(viewPath) || this.#cachePaths.set(viewPath, this.resolve(viewPath)).get(viewPath)!;\n const engine = this.getEngine(extension);\n\n if (!engine) {\n throw new Error(`Engine not found to render the following \"${viewPath}\"`);\n }\n\n return engine.render(path, Object.assign({cache: this.cache || this.env === Env.PROD}, engine.options, options));\n }\n\n protected getExtension(viewPath: string) {\n return (extname(viewPath) || this.viewEngine).replace(/\\./, \"\");\n }\n\n protected resolve(viewPath: string) {\n const extension = this.getExtension(viewPath);\n\n viewPath = viewPath.replace(extname(viewPath), \"\") + \".\" + extension;\n\n const path =\n [\n viewPath,\n resolve(join(this.root, viewPath)),\n resolve(join(process.cwd(), \"views\", viewPath)),\n resolve(join(process.cwd(), \"public\", viewPath))\n ].find((file) => Fs.existsSync(file)) || viewPath;\n\n return {\n path,\n extension\n };\n }\n}\n"],"names":["View","path","options","StoreSet","PLATFORM_VIEWS_EXTENSIONS","atpl","bracket","dot","dust","ect","ejs","haml","hamlet","hbs","handlebars","hogan","htmling","jazz","jqtpl","just","kernel","liquid","liquor","lodash","mote","mustache","nunjucks","plates","pug","qejs","ractive","razor","jsx","slm","squirelly","swig","teacup","templayed","toffee","twig","underscore","vash","velocityjs","walrus","whiskers","patchEJS","compile","str","require","tryImport","name","er","PlatformViews","constructor","Map","$onInit","disabled","Object","entries","extensionsOptions","loadFromConsolidate","loadFromTsedEngines","cons","requires","forEach","engineType","getEngineOptions","registerEngine","render","tsed","set","get","engines","has","getEngine","getEngines","map","extension","engine","getExtension","type","getValue","engineOptions","viewPath","resolve","Error","assign","cache","env","Env","PROD","extname","viewEngine","replace","join","root","process","cwd","find","file","Fs","existsSync","__decorate","Constant","Module","views","exists"],"mappings":";;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;SAsBgBA,KAAKC,MAAcC;AACjC,SAAOC,QAAQ,CAAC,MAAD,EAAS;AAACF,IAAAA,IAAD;AAAOC,IAAAA;AAAP,GAAT,CAAf;AACD;;MCxBYE,yBAAyB,GAAG;AACvCC,EAAAA,IAAI,EAAE,MADiC;AAEvCC,EAAAA,OAAO,EAAE,SAF8B;AAGvCC,EAAAA,GAAG,EAAE,KAHkC;AAIvCC,EAAAA,IAAI,EAAE,MAJiC;AAKvCC,EAAAA,GAAG,EAAE,KALkC;AAMvCC,EAAAA,GAAG,EAAE,KANkC;AAOvCC,EAAAA,IAAI,EAAE,MAPiC;AAQvC,iBAAe,aARwB;AASvCC,EAAAA,MAAM,EAAE,QAT+B;AAUvCC,EAAAA,GAAG,EAAE,YAVkC;AAWvCC,EAAAA,UAAU,EAAE,YAX2B;AAYvCC,EAAAA,KAAK,EAAE,OAZgC;AAavCC,EAAAA,OAAO,EAAE,SAb8B;AAcvCC,EAAAA,IAAI,EAAE,MAdiC;AAevCC,EAAAA,KAAK,EAAE,OAfgC;AAgBvC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,EAAYZ,QAAZ,CAAL,CAFT,EAGEC,OAAO,CAACU,IAAI,CAACE,OAAO,CAACC,GAAR,EAAD,EAAgB,OAAhB,EAAyBd,QAAzB,CAAL,CAHT,EAIEC,OAAO,CAACU,IAAI,CAACE,OAAO,CAACC,GAAR,EAAD,EAAgB,QAAhB,EAA0Bd,QAA1B,CAAL,CAJT,EAKEe,IALF,CAKQC,IAAD,IAAUC,EAAE,CAACC,UAAH,CAAcF,IAAd,CALjB,KAKyChB,QAN3C;AAQA,WAAO;AACLlF,MAAAA,IADK;AAEL4E,MAAAA;AAFK,KAAP;AAID;;CAjJuB;;AAExByB,YADCC,QAAQ,CAAC,KAAD,8EACT;;AAGAD,YADCC,QAAQ,CAAC,YAAD,KAAkBP,OAAO,CAACC,GAAR,UAAlB,+EACT;;AAGAK,YADCC,QAAQ,CAAC,aAAD,iFACT;;AAGAD,YADCC,QAAQ,CAAC,gBAAD,EAAmB,KAAnB,mFACT;;AAGAD,YADCC,QAAQ,CAAC,kBAAD,EAAqB,KAArB,qFACT;;AAGAD,YADCC,QAAQ,CAAC,kBAAD,EAAqB,EAArB,4FACT;;AAGAD,YADCC,QAAQ,CAAC,eAAD,EAAkB,EAAlB,wFACT;;AApBWnD,aAAa,eALzBoD,MAAM,CAAC;AACNC,EAAAA,KAAK,EAAE;AACLC,IAAAA,MAAM,EAAE;AADH;AADD,CAAD,IAKMtD,cAAA;;;;"}
|
|
@@ -8,6 +8,7 @@ export declare class PlatformViews {
|
|
|
8
8
|
env: Env;
|
|
9
9
|
readonly root: string;
|
|
10
10
|
readonly cache: boolean;
|
|
11
|
+
readonly disabled: string;
|
|
11
12
|
readonly viewEngine: string;
|
|
12
13
|
protected extensionsOptions: PlatformViewsExtensionsTypes;
|
|
13
14
|
protected engineOptions: Record<string, PlatformViewsEngineOptions>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-views",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.88.1",
|
|
4
4
|
"description": "Views module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"tslib": "2.2.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@tsed/core": "6.
|
|
23
|
-
"@tsed/di": "6.
|
|
22
|
+
"@tsed/core": "6.88.1",
|
|
23
|
+
"@tsed/di": "6.88.1",
|
|
24
24
|
"@tsed/engines": "^1.1.5",
|
|
25
|
-
"@tsed/exceptions": "6.
|
|
26
|
-
"@tsed/schema": "6.
|
|
25
|
+
"@tsed/exceptions": "6.88.1",
|
|
26
|
+
"@tsed/schema": "6.88.1",
|
|
27
27
|
"@types/consolidate": "0.14.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@tsed/core": "^6.
|
|
31
|
-
"@tsed/di": "^6.
|
|
30
|
+
"@tsed/core": "^6.88.1",
|
|
31
|
+
"@tsed/di": "^6.88.1",
|
|
32
32
|
"@tsed/engines": "^1.1.5",
|
|
33
|
-
"@tsed/exceptions": "^6.
|
|
34
|
-
"@tsed/schema": "^6.
|
|
33
|
+
"@tsed/exceptions": "^6.88.1",
|
|
34
|
+
"@tsed/schema": "^6.88.1"
|
|
35
35
|
},
|
|
36
36
|
"repository": "https://github.com/tsedio/tsed",
|
|
37
37
|
"bugs": {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Type } from "@tsed/core";
|
|
2
|
-
import { InternalServerError } from "@tsed/exceptions";
|
|
3
|
-
/**
|
|
4
|
-
* @private
|
|
5
|
-
*/
|
|
6
|
-
export declare class TemplateRenderError extends InternalServerError {
|
|
7
|
-
name: string;
|
|
8
|
-
constructor(target: Type<any> | string, method: string | symbol, err: Error);
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @returns {string}
|
|
12
|
-
*/
|
|
13
|
-
static buildMessage(target: Type<any> | string, method: string | symbol, err: Error): string;
|
|
14
|
-
}
|