@tstdl/base 0.71.54 → 0.71.57
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/data-structures/index.d.ts +1 -0
- package/data-structures/index.js +1 -0
- package/data-structures/index.js.map +1 -1
- package/data-structures/set.d.ts +18 -0
- package/data-structures/set.js +59 -0
- package/data-structures/set.js.map +1 -0
- package/disposable/disposable.js +2 -2
- package/disposable/disposable.js.map +1 -1
- package/examples/mail/basic.d.ts +1 -0
- package/examples/mail/basic.js +33 -0
- package/examples/mail/basic.js.map +1 -0
- package/examples/pdf/basic.d.ts +1 -0
- package/examples/pdf/basic.js +23 -0
- package/examples/pdf/basic.js.map +1 -0
- package/image-service/image-service.d.ts +1 -1
- package/mail/mail.service.d.ts +1 -0
- package/mail/mail.service.js +7 -1
- package/mail/mail.service.js.map +1 -1
- package/mail/models/mail-log.model.d.ts +3 -3
- package/mail/models/mail-template.model.d.ts +0 -1
- package/mail/template-providers/file-mail-template.provider.d.ts +4 -6
- package/mail/template-providers/file-mail-template.provider.js +3 -27
- package/mail/template-providers/file-mail-template.provider.js.map +1 -1
- package/mail/template-providers/memory-mail-template.provider.d.ts +3 -5
- package/mail/template-providers/memory-mail-template.provider.js +2 -14
- package/mail/template-providers/memory-mail-template.provider.js.map +1 -1
- package/mail/template-renderers/handlebars.mail-template-renderer.d.ts +6 -4
- package/mail/template-renderers/handlebars.mail-template-renderer.js +25 -10
- package/mail/template-renderers/handlebars.mail-template-renderer.js.map +1 -1
- package/mail/template-renderers/mjml.mail-template-renderer.d.ts +6 -7
- package/mail/template-renderers/mjml.mail-template-renderer.js +28 -30
- package/mail/template-renderers/mjml.mail-template-renderer.js.map +1 -1
- package/package.json +7 -5
- package/pdf/index.d.ts +1 -0
- package/pdf/index.js +18 -0
- package/pdf/index.js.map +1 -0
- package/pdf/pdf.service.d.ts +17 -0
- package/pdf/pdf.service.js +62 -0
- package/pdf/pdf.service.js.map +1 -0
- package/pool/index.d.ts +1 -0
- package/pool/index.js +18 -0
- package/pool/index.js.map +1 -0
- package/pool/pool.d.ts +24 -0
- package/pool/pool.js +84 -0
- package/pool/pool.js.map +1 -0
- package/templates/index.d.ts +7 -0
- package/templates/index.js +24 -0
- package/templates/index.js.map +1 -0
- package/templates/module.d.ts +12 -0
- package/templates/module.js +24 -0
- package/templates/module.js.map +1 -0
- package/templates/providers/file-template.provider.base.d.ts +12 -0
- package/templates/providers/file-template.provider.base.js +43 -0
- package/templates/providers/file-template.provider.base.js.map +1 -0
- package/templates/providers/file-template.provider.d.ts +21 -0
- package/templates/providers/file-template.provider.js +44 -0
- package/templates/providers/file-template.provider.js.map +1 -0
- package/templates/providers/memory-template.provider.base.d.ts +9 -0
- package/templates/providers/memory-template.provider.base.js +35 -0
- package/templates/providers/memory-template.provider.base.js.map +1 -0
- package/templates/providers/memory-template.provider.d.ts +4 -0
- package/templates/providers/memory-template.provider.js +18 -0
- package/templates/providers/memory-template.provider.js.map +1 -0
- package/templates/renderers/handlebars.template-renderer.d.ts +11 -0
- package/templates/renderers/handlebars.template-renderer.js +27 -0
- package/templates/renderers/handlebars.template-renderer.js.map +1 -0
- package/templates/renderers/mjml.template-renderer.d.ts +15 -0
- package/templates/renderers/mjml.template-renderer.js +54 -0
- package/templates/renderers/mjml.template-renderer.js.map +1 -0
- package/templates/template-renderer.provider.d.ts +8 -0
- package/templates/template-renderer.provider.js +60 -0
- package/templates/template-renderer.provider.js.map +1 -0
- package/templates/template.model.d.ts +5 -0
- package/templates/template.model.js +3 -0
- package/templates/template.model.js.map +1 -0
- package/templates/template.provider.d.ts +4 -0
- package/templates/template.provider.js +7 -0
- package/templates/template.provider.js.map +1 -0
- package/templates/template.renderer.d.ts +6 -0
- package/templates/template.renderer.js +7 -0
- package/templates/template.renderer.js.map +1 -0
- package/templates/template.service.d.ts +11 -0
- package/templates/template.service.js +37 -0
- package/templates/template.service.js.map +1 -0
- package/templates/tokens.d.ts +3 -0
- package/templates/tokens.js +6 -0
- package/templates/tokens.js.map +1 -0
|
@@ -8,55 +8,53 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.MjmlMailTemplateRenderer = void 0;
|
|
16
13
|
const container_1 = require("../../container");
|
|
14
|
+
const templates_1 = require("../../templates");
|
|
15
|
+
const mjml_template_renderer_1 = require("../../templates/renderers/mjml.template-renderer");
|
|
17
16
|
const type_guards_1 = require("../../utils/type-guards");
|
|
18
|
-
// @ts-expect-error import is actually working
|
|
19
|
-
const mjml2html = require("mjml");
|
|
20
|
-
const mail_template_renderer_provider_1 = require("../mail-template-renderer.provider");
|
|
21
17
|
const mail_template_renderer_1 = require("../mail-template.renderer");
|
|
18
|
+
(0, templates_1.configureTemplates)({ templateRenderers: [mjml_template_renderer_1.MjmlTemplateRenderer] });
|
|
22
19
|
let MjmlMailTemplateRenderer = class MjmlMailTemplateRenderer extends mail_template_renderer_1.MailTemplateRenderer {
|
|
23
|
-
constructor(rendererProvider) {
|
|
20
|
+
constructor(rendererProvider, mjmlTemplateRenderer) {
|
|
24
21
|
super();
|
|
25
22
|
this.rendererProvider = rendererProvider;
|
|
23
|
+
this.mjmlTemplateRenderer = mjmlTemplateRenderer;
|
|
26
24
|
}
|
|
27
25
|
canHandleType(type) {
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
if (!type.startsWith('mjml-')) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const parent = type.slice(5);
|
|
35
|
-
return this.rendererProvider.has(parent);
|
|
26
|
+
return this.mjmlTemplateRenderer.canHandleType(type);
|
|
36
27
|
}
|
|
37
28
|
async render(template, context) {
|
|
38
|
-
var _a;
|
|
39
|
-
if (template.type
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
if (template.type == 'mjml') {
|
|
31
|
+
const mjmlTemplate = (0, type_guards_1.isDefined)(template.html) ? {
|
|
32
|
+
type: template.type,
|
|
33
|
+
template: template.html
|
|
34
|
+
} : undefined;
|
|
35
|
+
const html = (0, type_guards_1.isDefined)(mjmlTemplate)
|
|
36
|
+
? await this.mjmlTemplateRenderer.render(mjmlTemplate)
|
|
37
|
+
: undefined;
|
|
38
|
+
return {
|
|
39
|
+
subject: template.subject,
|
|
44
40
|
html,
|
|
45
|
-
text
|
|
46
|
-
|
|
41
|
+
text: template.text
|
|
42
|
+
};
|
|
47
43
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const parent = template.type.slice(5);
|
|
45
|
+
const renderer = this.rendererProvider.get(parent);
|
|
46
|
+
const subject = (0, type_guards_1.isDefined)(template.subject) ? await renderer.render({ type: parent, template: template.subject, options: (_a = template.options) === null || _a === void 0 ? void 0 : _a.preprocessorOptions }, context) : undefined;
|
|
47
|
+
const html = (0, type_guards_1.isDefined)(template.html) ? await renderer.render({ type: parent, template: template.html, options: (_b = template.options) === null || _b === void 0 ? void 0 : _b.preprocessorOptions }, context) : undefined;
|
|
48
|
+
const text = (0, type_guards_1.isDefined)(template.text) ? await renderer.render({ type: parent, template: template.text, options: (_c = template.options) === null || _c === void 0 ? void 0 : _c.preprocessorOptions }, context) : undefined;
|
|
49
|
+
const preprocessedTemplate = Object.assign(Object.assign({}, template), { type: 'mjml', subject,
|
|
51
50
|
html,
|
|
52
|
-
text
|
|
53
|
-
|
|
51
|
+
text });
|
|
52
|
+
return this.render(preprocessedTemplate);
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
55
|
MjmlMailTemplateRenderer = __decorate([
|
|
57
56
|
(0, container_1.singleton)(),
|
|
58
|
-
|
|
59
|
-
__metadata("design:paramtypes", [mail_template_renderer_provider_1.MailTemplateRendererProvider])
|
|
57
|
+
__metadata("design:paramtypes", [templates_1.TemplateRendererProvider, mjml_template_renderer_1.MjmlTemplateRenderer])
|
|
60
58
|
], MjmlMailTemplateRenderer);
|
|
61
59
|
exports.MjmlMailTemplateRenderer = MjmlMailTemplateRenderer;
|
|
62
60
|
//# sourceMappingURL=mjml.mail-template-renderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mjml.mail-template-renderer.js","sourceRoot":"","sources":["../../../source/mail/template-renderers/mjml.mail-template-renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mjml.mail-template-renderer.js","sourceRoot":"","sources":["../../../source/mail/template-renderers/mjml.mail-template-renderer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAwC;AACxC,+CAA2E;AAE3E,6FAAoF;AACpF,yDAAgD;AAEhD,sEAAiE;AAKjE,IAAA,8BAAkB,EAAC,EAAE,iBAAiB,EAAE,CAAC,6CAAoB,CAAC,EAAE,CAAC,CAAC;AAGlE,IAAa,wBAAwB,GAArC,MAAa,wBAAyB,SAAQ,6CAAsC;IAIlF,YAAY,gBAA0C,EAAE,oBAA0C;QAChG,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,CAAC;IAED,aAAa,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,QAA0B,EAAE,OAAgB;;QACvD,IAAI,QAAQ,CAAC,IAAI,IAAI,MAAM,EAAE;YAC3B,MAAM,YAAY,GAA6B,IAAA,uBAAS,EAAC,QAAQ,CAAC,IAAI,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AAC,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAA,QAAQ,CAAC,OAAO,0CAAE,mBAAmB,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE9K,MAAM,oBAAoB,mCACrB,QAAQ,KACX,IAAI,EAAE,MAAM,EACZ,OAAO;YACP,IAAI;YACJ,IAAI,GACL,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAlDY,wBAAwB;IADpC,IAAA,qBAAS,GAAE;qCAKoB,oCAAwB,EAAwB,6CAAoB;GAJvF,wBAAwB,CAkDpC;AAlDY,4DAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.57",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"luxon": "^2",
|
|
19
19
|
"reflect-metadata": "^0.1",
|
|
20
|
-
"rxjs": "^7"
|
|
20
|
+
"rxjs": "^7",
|
|
21
|
+
"type-fest": "^2"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/chroma-js": "^2.1",
|
|
@@ -28,8 +29,8 @@
|
|
|
28
29
|
"@types/node": ">=16",
|
|
29
30
|
"@types/nodemailer": "^6.4.4",
|
|
30
31
|
"@types/yup": "0.29",
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
32
|
-
"@typescript-eslint/parser": "5.
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "5.28",
|
|
33
|
+
"@typescript-eslint/parser": "5.28",
|
|
33
34
|
"eslint": "8.17",
|
|
34
35
|
"ttypescript": "1.5",
|
|
35
36
|
"typedoc": "0.22",
|
|
@@ -48,8 +49,9 @@
|
|
|
48
49
|
"mjml": "^4.12",
|
|
49
50
|
"mongodb": "^4.7",
|
|
50
51
|
"nodemailer": "^6.7",
|
|
52
|
+
"puppeteer": "^14.4.0",
|
|
51
53
|
"superstruct": "^0.16",
|
|
52
|
-
"undici": "^5.
|
|
54
|
+
"undici": "^5.5",
|
|
53
55
|
"urlpattern-polyfill": "^4.0"
|
|
54
56
|
},
|
|
55
57
|
"peerDependenciesMeta": {
|
package/pdf/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pdf.service';
|
package/pdf/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pdf.service"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/pdf/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/pdf/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AfterResolve } from "../container";
|
|
2
|
+
import { afterResolve } from "../container";
|
|
3
|
+
import type { AsyncDisposable } from "../disposable/disposable";
|
|
4
|
+
import { disposeAsync } from "../disposable/disposable";
|
|
5
|
+
import { TemplateService } from "../templates";
|
|
6
|
+
export declare class PdfService implements AsyncDisposable, AfterResolve {
|
|
7
|
+
private readonly templateService;
|
|
8
|
+
private readonly pool;
|
|
9
|
+
constructor(templateService: TemplateService);
|
|
10
|
+
[afterResolve](): void;
|
|
11
|
+
[disposeAsync](): Promise<void>;
|
|
12
|
+
dispose(): Promise<void>;
|
|
13
|
+
renderHtml(html: string): Promise<Uint8Array>;
|
|
14
|
+
renderUrl(url: string): Promise<Uint8Array>;
|
|
15
|
+
renderTemplate(key: string, templateContext: object): Promise<Uint8Array>;
|
|
16
|
+
private render;
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PdfService = void 0;
|
|
13
|
+
const container_1 = require("../container");
|
|
14
|
+
const core_1 = require("../core");
|
|
15
|
+
const disposable_1 = require("../disposable/disposable");
|
|
16
|
+
const pool_1 = require("../pool");
|
|
17
|
+
const templates_1 = require("../templates");
|
|
18
|
+
const puppeteer = require("puppeteer");
|
|
19
|
+
let PdfService = class PdfService {
|
|
20
|
+
constructor(templateService) {
|
|
21
|
+
this.templateService = templateService;
|
|
22
|
+
this.pool = new pool_1.Pool(async () => puppeteer.launch(), async (browser) => browser.close());
|
|
23
|
+
}
|
|
24
|
+
[container_1.afterResolve]() {
|
|
25
|
+
core_1.disposer.add(this);
|
|
26
|
+
}
|
|
27
|
+
async [disposable_1.disposeAsync]() {
|
|
28
|
+
return this.dispose();
|
|
29
|
+
}
|
|
30
|
+
async dispose() {
|
|
31
|
+
return this.pool.dispose();
|
|
32
|
+
}
|
|
33
|
+
async renderHtml(html) {
|
|
34
|
+
return this.render(async (page) => page.setContent(html, { waitUntil: 'networkidle2' }));
|
|
35
|
+
}
|
|
36
|
+
async renderUrl(url) {
|
|
37
|
+
return this.render(async (page) => page.goto(url, { waitUntil: 'networkidle2' }));
|
|
38
|
+
}
|
|
39
|
+
async renderTemplate(key, templateContext) {
|
|
40
|
+
const html = await this.templateService.render(key, templateContext);
|
|
41
|
+
return this.renderHtml(html);
|
|
42
|
+
}
|
|
43
|
+
async render(handler) {
|
|
44
|
+
return this.pool.use(async (browser) => {
|
|
45
|
+
const page = await browser.newPage();
|
|
46
|
+
try {
|
|
47
|
+
await handler(page);
|
|
48
|
+
const result = await page.pdf({ format: 'a4' });
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
await page.close();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
PdfService = __decorate([
|
|
58
|
+
(0, container_1.singleton)(),
|
|
59
|
+
__metadata("design:paramtypes", [templates_1.TemplateService])
|
|
60
|
+
], PdfService);
|
|
61
|
+
exports.PdfService = PdfService;
|
|
62
|
+
//# sourceMappingURL=pdf.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf.service.js","sourceRoot":"","sources":["../../source/pdf/pdf.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,4CAAsD;AACtD,kCAAkC;AAElC,yDAAuD;AACvD,kCAA8B;AAC9B,4CAA8C;AAC9C,uCAAuC;AAGvC,IAAa,UAAU,GAAvB,MAAa,UAAU;IAIrB,YAAY,eAAgC;QAC1C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAClB,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAC9B,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CACnC,CAAC;IACJ,CAAC;IAED,CAAC,wBAAY,CAAC;QACZ,eAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,CAAC,yBAAY,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW,EAAE,eAAuB;QACvD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACrC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;YAErC,IAAI;gBACF,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBACpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBAChD,OAAO,MAAM,CAAC;aACf;oBACO;gBACN,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AApDY,UAAU;IADtB,IAAA,qBAAS,GAAE;qCAKmB,2BAAe;GAJjC,UAAU,CAoDtB;AApDY,gCAAU"}
|
package/pool/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pool';
|
package/pool/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pool"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/pool/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB"}
|
package/pool/pool.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AsyncDisposable } from "../disposable/disposable";
|
|
2
|
+
import { disposeAsync } from "../disposable/disposable";
|
|
3
|
+
export declare type PoolOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* maximum number of instances
|
|
6
|
+
* @default number of cpu cores
|
|
7
|
+
*/
|
|
8
|
+
size?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare type PoolInstanceFactory<T> = () => T | Promise<T>;
|
|
11
|
+
export declare type PoolInstanceDisposer<T> = (instance: T) => void | Promise<void>;
|
|
12
|
+
export declare class Pool<T> implements AsyncDisposable {
|
|
13
|
+
private readonly size;
|
|
14
|
+
private readonly freeInstances;
|
|
15
|
+
private readonly usedInstances;
|
|
16
|
+
private readonly factory;
|
|
17
|
+
private readonly disposer;
|
|
18
|
+
private disposed;
|
|
19
|
+
get length(): number;
|
|
20
|
+
constructor(factory: PoolInstanceFactory<T>, disposer: PoolInstanceDisposer<T>, options?: PoolOptions);
|
|
21
|
+
dispose(): Promise<void>;
|
|
22
|
+
[disposeAsync](): Promise<void>;
|
|
23
|
+
use<R>(handler: (instance: T) => R | Promise<R>): Promise<R>;
|
|
24
|
+
}
|
package/pool/pool.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pool = void 0;
|
|
4
|
+
const data_structures_1 = require("../data-structures");
|
|
5
|
+
const set_1 = require("../data-structures/set");
|
|
6
|
+
const disposable_1 = require("../disposable/disposable");
|
|
7
|
+
const os_1 = require("os");
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
const placeholder = Symbol('pool placeholder');
|
|
10
|
+
class Pool {
|
|
11
|
+
constructor(factory, disposer, options) {
|
|
12
|
+
var _a;
|
|
13
|
+
this.size = (_a = options === null || options === void 0 ? void 0 : options.size) !== null && _a !== void 0 ? _a : (0, os_1.cpus)().length;
|
|
14
|
+
this.factory = factory;
|
|
15
|
+
this.disposer = disposer;
|
|
16
|
+
this.freeInstances = new data_structures_1.ArrayList();
|
|
17
|
+
this.usedInstances = new set_1.Set();
|
|
18
|
+
this.disposed = false;
|
|
19
|
+
}
|
|
20
|
+
get length() {
|
|
21
|
+
return this.freeInstances.size + this.usedInstances.size;
|
|
22
|
+
}
|
|
23
|
+
async dispose() {
|
|
24
|
+
return this[disposable_1.disposeAsync]();
|
|
25
|
+
}
|
|
26
|
+
async [disposable_1.disposeAsync]() {
|
|
27
|
+
this.disposed = true;
|
|
28
|
+
while (this.freeInstances.size > 0) {
|
|
29
|
+
const instance = this.freeInstances.removeFirst();
|
|
30
|
+
await this.disposer(instance);
|
|
31
|
+
}
|
|
32
|
+
for (const instance of this.usedInstances) {
|
|
33
|
+
if (instance[placeholder] != true) {
|
|
34
|
+
await this.disposer(instance);
|
|
35
|
+
}
|
|
36
|
+
this.usedInstances.delete(instance);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
40
|
+
async use(handler) {
|
|
41
|
+
let instance;
|
|
42
|
+
if (this.freeInstances.hasItems) {
|
|
43
|
+
instance = this.freeInstances.removeFirst();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (this.length >= this.size) {
|
|
47
|
+
await (0, rxjs_1.firstValueFrom)((0, rxjs_1.race)(this.freeInstances.change$, this.usedInstances.change$));
|
|
48
|
+
return this.use(handler);
|
|
49
|
+
}
|
|
50
|
+
const tempInstance = { [placeholder]: true };
|
|
51
|
+
this.usedInstances.add(tempInstance);
|
|
52
|
+
try {
|
|
53
|
+
instance = await this.factory();
|
|
54
|
+
if (this.disposed) {
|
|
55
|
+
await this.disposer(instance);
|
|
56
|
+
throw new Error('Pool was disposed.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
this.usedInstances.delete(tempInstance);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
this.usedInstances.add(instance);
|
|
64
|
+
try {
|
|
65
|
+
const result = await handler(instance);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
try {
|
|
70
|
+
await this.disposer(instance);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
this.usedInstances.delete(instance);
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
this.usedInstances.delete(instance);
|
|
79
|
+
this.freeInstances.add(instance);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Pool = Pool;
|
|
84
|
+
//# sourceMappingURL=pool.js.map
|
package/pool/pool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../source/pool/pool.ts"],"names":[],"mappings":";;;AAAA,wDAA8C;AAC9C,gDAA4C;AAE5C,yDAAuD;AACvD,2BAA0B;AAC1B,+BAA4C;AAa5C,MAAM,WAAW,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE/C,MAAa,IAAI;IAaf,YAAY,OAA+B,EAAE,QAAiC,EAAE,OAAqB;;QACnG,I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AQ,CAAC,CAAC;SAClC;IACH,CAAC;CACF;AA9FD,oBA8FC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./module"), exports);
|
|
18
|
+
__exportStar(require("./template-renderer.provider"), exports);
|
|
19
|
+
__exportStar(require("./template.model"), exports);
|
|
20
|
+
__exportStar(require("./template.provider"), exports);
|
|
21
|
+
__exportStar(require("./template.renderer"), exports);
|
|
22
|
+
__exportStar(require("./template.service"), exports);
|
|
23
|
+
__exportStar(require("./tokens"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/templates/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+DAA6C;AAC7C,mDAAiC;AACjC,sDAAoC;AACpC,sDAAoC;AACpC,qDAAmC;AACnC,2CAAyB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Type } from "../types";
|
|
2
|
+
import { TemplateProvider } from './template.provider';
|
|
3
|
+
import type { TemplateRenderer } from './template.renderer';
|
|
4
|
+
export declare type TemplateModuleConfig = {
|
|
5
|
+
templateProvider: Type<TemplateProvider>;
|
|
6
|
+
templateRenderers: Type<TemplateRenderer>[];
|
|
7
|
+
};
|
|
8
|
+
export declare const templateModuleConfig: TemplateModuleConfig;
|
|
9
|
+
/**
|
|
10
|
+
* configure mail module
|
|
11
|
+
*/
|
|
12
|
+
export declare function configureTemplates({ templateProvider, templateRenderers }?: Partial<TemplateModuleConfig>): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configureTemplates = exports.templateModuleConfig = void 0;
|
|
4
|
+
const container_1 = require("../container");
|
|
5
|
+
const type_guards_1 = require("../utils/type-guards");
|
|
6
|
+
const template_provider_1 = require("./template.provider");
|
|
7
|
+
const tokens_1 = require("./tokens");
|
|
8
|
+
exports.templateModuleConfig = {
|
|
9
|
+
templateProvider: (0, container_1.stubClass)(template_provider_1.TemplateProvider),
|
|
10
|
+
templateRenderers: []
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* configure mail module
|
|
14
|
+
*/
|
|
15
|
+
function configureTemplates({ templateProvider, templateRenderers } = {}) {
|
|
16
|
+
exports.templateModuleConfig.templateProvider = templateProvider !== null && templateProvider !== void 0 ? templateProvider : exports.templateModuleConfig.templateProvider;
|
|
17
|
+
exports.templateModuleConfig.templateRenderers = [...new Set([...exports.templateModuleConfig.templateRenderers, ...(templateRenderers !== null && templateRenderers !== void 0 ? templateRenderers : [])])];
|
|
18
|
+
if ((0, type_guards_1.isDefined)(templateProvider)) {
|
|
19
|
+
container_1.container.registerSingleton(template_provider_1.TemplateProvider, { useToken: templateProvider });
|
|
20
|
+
}
|
|
21
|
+
container_1.container.registerSingleton(tokens_1.TEMPLATE_RENDERERS, { useValue: exports.templateModuleConfig.templateRenderers });
|
|
22
|
+
}
|
|
23
|
+
exports.configureTemplates = configureTemplates;
|
|
24
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../source/templates/module.ts"],"names":[],"mappings":";;;AAAA,4CAAmD;AAEnD,sDAAgD;AAChD,2DAAuD;AAEvD,qCAA8C;AAOjC,QAAA,oBAAoB,GAAyB;IACxD,gBAAgB,EAAE,IAAA,qBAAS,EAAC,oCAAgB,CAAC;IAC7C,iBAAiB,EAAE,EAAE;CACtB,CAAC;AAEF;;GAEG;AACH,SAAgB,kBAAkB,CAAC,EAAE,gBAAgB,EAAE,iBAAiB,KAAoC,EAAE;IAC5G,4BAAoB,CAAC,gBAAgB,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,4BAAoB,CAAC,gBAAgB,CAAC;IAClG,4BAAoB,CAAC,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,4BAAoB,CAAC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjI,IAAI,IAAA,uBAAS,EAAC,gBAAgB,CAAC,EAAE;QAC/B,qBAAS,CAAC,iBAAiB,CAAC,oCAAgB,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC;KAC/E;IAED,qBAAS,CAAC,iBAAiB,CAAC,2BAAkB,EAAE,EAAE,QAAQ,EAAE,4BAAoB,CAAC,iBAAiB,EAAE,CAAC,CAAC;AACxG,CAAC;AATD,gDASC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Schema } from "../../schema";
|
|
2
|
+
import type { TypedOmit } from "../../types";
|
|
3
|
+
import type { Template } from '../template.model';
|
|
4
|
+
export declare type FileTemplateBase = TypedOmit<Template, 'template'>;
|
|
5
|
+
export declare type FileForward<T extends FileTemplateBase, U extends FileTemplateBase> = [fileKey: keyof U, targetKey: keyof T];
|
|
6
|
+
export declare class FileTemplateProviderBase<T extends FileTemplateBase, U extends FileTemplateBase> {
|
|
7
|
+
private readonly schema;
|
|
8
|
+
private readonly basePath;
|
|
9
|
+
private readonly fileForwards;
|
|
10
|
+
constructor(schema: Schema<U>, basePath: string, fileForwards: FileForward<T, U>[]);
|
|
11
|
+
get(key: string): Promise<T>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileTemplateProviderBase = void 0;
|
|
4
|
+
const type_guards_1 = require("../../utils/type-guards");
|
|
5
|
+
const fs = require("fs/promises");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
class FileTemplateProviderBase {
|
|
8
|
+
constructor(schema, basePath, fileForwards) {
|
|
9
|
+
this.schema = schema;
|
|
10
|
+
this.basePath = basePath;
|
|
11
|
+
this.fileForwards = new Map(fileForwards);
|
|
12
|
+
}
|
|
13
|
+
async get(key) {
|
|
14
|
+
const filePath = path.resolve(this.basePath, `${key}.json`);
|
|
15
|
+
const fileContent = await fs.readFile(filePath, { encoding: 'utf8' });
|
|
16
|
+
const fileTemplate = this.schema.parse(JSON.parse(fileContent));
|
|
17
|
+
const result = {};
|
|
18
|
+
const entries = Object.entries(fileTemplate);
|
|
19
|
+
for (const [property, value] of entries) {
|
|
20
|
+
if (!this.fileForwards.has(property)) {
|
|
21
|
+
result[property] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const [fileKey, targetKey] of this.fileForwards) {
|
|
25
|
+
if ((0, type_guards_1.isDefined)(result[targetKey])) {
|
|
26
|
+
if ((0, type_guards_1.isDefined)(fileTemplate[fileKey])) {
|
|
27
|
+
throw new Error(`Either ${fileKey.toString()} or ${targetKey.toString()} must be defined.`);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if ((0, type_guards_1.isDefined)(fileTemplate[fileKey])) {
|
|
32
|
+
const contentFilePath = (0, type_guards_1.assertStringPass)(fileTemplate[fileKey], 'File path must be a string.');
|
|
33
|
+
const content = await fs.readFile(path.resolve(this.basePath, contentFilePath), { encoding: 'utf8' });
|
|
34
|
+
result[targetKey] = content;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Either ${fileKey.toString()} or ${targetKey.toString()} must be defined.`);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.FileTemplateProviderBase = FileTemplateProviderBase;
|
|
43
|
+
//# sourceMappingURL=file-template.provider.base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-template.provider.base.js","sourceRoot":"","sources":["../../../source/templates/providers/file-template.provider.base.ts"],"names":[],"mappings":";;;AAEA,yDAAkE;AAClE,kCAAkC;AAClC,6BAA6B;AAO7B,MAAa,wBAAwB;IAKnC,YAAY,MAAiB,EAAE,QAAgB,EAAE,YAAiC;QAChF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC;QAC5D,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACtE,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QAEhE,MAAM,MAAM,GAAW,E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@@
|
|
|
1
|
+
import type { Injectable } from "../../container";
|
|
2
|
+
import { resolveArgumentType } from "../../container";
|
|
3
|
+
import type { Template } from '../template.model';
|
|
4
|
+
import type { TemplateProvider } from '../template.provider';
|
|
5
|
+
import type { FileTemplateBase } from './file-template.provider.base';
|
|
6
|
+
import { FileTemplateProviderBase } from './file-template.provider.base';
|
|
7
|
+
export declare type FileTemplate = FileTemplateBase & {
|
|
8
|
+
template?: string;
|
|
9
|
+
/** subject template file */
|
|
10
|
+
templateFile?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type FileTemplateProviderConfig = {
|
|
13
|
+
basePath?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type FileTemplateProviderArgument = string;
|
|
16
|
+
export declare const fileTemplateProviderConfig: FileTemplateProviderConfig;
|
|
17
|
+
export declare class FileTemplateProvider extends FileTemplateProviderBase<Template, FileTemplate> implements TemplateProvider, Injectable<FileTemplateProviderArgument> {
|
|
18
|
+
readonly [resolveArgumentType]: FileTemplateProviderArgument;
|
|
19
|
+
constructor(basePath: string);
|
|
20
|
+
}
|
|
21
|
+
export declare function configureFileTemplateProvider(config?: Partial<FileTemplateProviderConfig>): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.configureFileTemplateProvider = exports.FileTemplateProvider = exports.fileTemplateProviderConfig = void 0;
|
|
16
|
+
const container_1 = require("../../container");
|
|
17
|
+
const schema_1 = require("../../schema");
|
|
18
|
+
const file_template_provider_base_1 = require("./file-template.provider.base");
|
|
19
|
+
exports.fileTemplateProviderConfig = {};
|
|
20
|
+
const fileTemplateSchema = (0, schema_1.object)({
|
|
21
|
+
type: (0, schema_1.string)(),
|
|
22
|
+
template: (0, schema_1.optional)((0, schema_1.string)()),
|
|
23
|
+
templateFile: (0, schema_1.optional)((0, schema_1.string)()),
|
|
24
|
+
options: (0, schema_1.optional)((0, schema_1.unknown)())
|
|
25
|
+
});
|
|
26
|
+
let FileTemplateProvider = class FileTemplateProvider extends file_template_provider_base_1.FileTemplateProviderBase {
|
|
27
|
+
constructor(basePath) {
|
|
28
|
+
super(fileTemplateSchema, basePath, [['templateFile', 'template']]);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
FileTemplateProvider = __decorate([
|
|
32
|
+
(0, container_1.singleton)({
|
|
33
|
+
defaultArgumentProvider: () => exports.fileTemplateProviderConfig.basePath
|
|
34
|
+
}),
|
|
35
|
+
__param(0, (0, container_1.injectArg)()),
|
|
36
|
+
__metadata("design:paramtypes", [String])
|
|
37
|
+
], FileTemplateProvider);
|
|
38
|
+
exports.FileTemplateProvider = FileTemplateProvider;
|
|
39
|
+
function configureFileTemplateProvider(config = {}) {
|
|
40
|
+
var _a;
|
|
41
|
+
exports.fileTemplateProviderConfig.basePath = (_a = config.basePath) !== null && _a !== void 0 ? _a : exports.fileTemplateProviderConfig.basePath;
|
|
42
|
+
}
|
|
43
|
+
exports.configureFileTemplateProvider = configureFileTemplateProvider;
|
|
44
|
+
//# sourceMappingURL=file-template.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-template.provider.js","sourceRoot":"","sources":["../../../source/templates/providers/file-template.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+CAAwE;AAExE,yCAA6D;AAI7D,+EAAyE;AAe5D,QAAA,0BAA0B,GAA+B,EAAE,CAAC;AAEzE,MAAM,kBAAkB,GAAyB,IAAA,eAAM,EAAC;IACtD,IAAI,EAAE,IAAA,eAAM,GAAE;IACd,QAAQ,EAAE,IAAA,iBAAQ,EAAC,IAAA,eAAM,GAAE,CAAC;IAC5B,YAAY,EAAE,IAAA,iBAAQ,EAAC,IAAA,eAAM,GAAE,CAAC;IAChC,OAAO,EAAE,IAAA,iBAAQ,EAAC,IAAA,gBAAO,GAAE,CAAC;CAC7B,CAAC,CAAC;AAKH,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,sDAAgD;IAGxF,YAAyB,QAAgB;QACvC,KAAK,CAAC,kBAAkB,EAAE,QAAQ,EAAE,CAAC,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;CACF,CAAA;AANY,oBAAoB;IAHhC,IAAA,qBAAS,EAAC;QACT,uBAAuB,EAAE,GAAG,EAAE,CAAC,kCAA0B,CAAC,QAAQ;KACnE,CAAC;IAIa,WAAA,IAAA,qBAAS,GAAE,CAAA;;GAHb,oBAAoB,CAMhC;AANY,oDAAoB;AAQjC,SAAgB,6BAA6B,CAAC,SAA8C,EAAE;;IAC5F,kCAA0B,CAAC,QAAQ,GAAG,MAAA,MAAM,CAAC,QAAQ,mCAAI,kCAA0B,CAAC,QAAQ,CAAC;AAC/F,CAAC;AAFD,sEAEC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TypedOmit } from "../../types";
|
|
2
|
+
import type { Template } from '../template.model';
|
|
3
|
+
export declare type MemoryTemplateBase = TypedOmit<Template, 'template'>;
|
|
4
|
+
export declare class MemoryTemplateProviderBase<T extends MemoryTemplateBase> {
|
|
5
|
+
private readonly map;
|
|
6
|
+
constructor();
|
|
7
|
+
add(key: string, template: T): void;
|
|
8
|
+
get(key: string): Promise<T>;
|
|
9
|
+
}
|