@spinajs/templates 2.0.180 → 2.0.181

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.
@@ -1,60 +1,60 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Templates } from './../index.js';
11
- import { Argument, CliCommand, Command, Option } from '@spinajs/cli';
12
- import { DI } from '@spinajs/di';
13
- import * as path from 'path';
14
- import * as fs from 'fs';
15
- import { Logger, Log } from '@spinajs/log-common';
16
- let RenderTemplateCommand = class RenderTemplateCommand extends CliCommand {
17
- async execute(template, options) {
18
- this.Log.trace(`Rendering ${template}, options: ${JSON.stringify(options)}`);
19
- try {
20
- const templates = await DI.resolve(Templates);
21
- let model = {};
22
- if (options.model && fs.existsSync(options.model)) {
23
- this.Log.trace(`Found model file at ${options.model}, trying to load model data ... `);
24
- const mText = fs.readFileSync(options.model, { encoding: 'utf-8' });
25
- model = JSON.parse(mText);
26
- }
27
- if (options && options.file) {
28
- this.Log.trace(`Rendering template to file ${options.file} ...`);
29
- const dir = path.dirname(options.file);
30
- if (!fs.existsSync(dir)) {
31
- this.Log.trace(`Directory ${dir} not exits, creating ...`);
32
- fs.mkdirSync(dir, { recursive: true });
33
- }
34
- await templates.renderToFile(template, model, options.file, options.lang);
35
- this.Log.success(`Rendering template ${template} to file ${options.file} succeded !`);
36
- return;
37
- }
38
- const result = await templates.render(template, model, options.lang);
39
- this.Log.success(`Rendering template ${template} succeded !`);
40
- // print out to console in raw format
41
- console.log(result);
42
- }
43
- catch (err) {
44
- this.Log.error(`Cannot render template ${template}, reason: ${err.message}, stack: ${err.stack}`);
45
- }
46
- }
47
- };
48
- __decorate([
49
- Logger('templates'),
50
- __metadata("design:type", Log)
51
- ], RenderTemplateCommand.prototype, "Log", void 0);
52
- RenderTemplateCommand = __decorate([
53
- Command('template-render', 'Renders template, usefull for template testing'),
54
- Argument('template', 'template path, must be in one of directory provided in configs'),
55
- Option('-f, --file [file]', false, 'path for file, where parsing result will be saved'),
56
- Option('-m, --model [model]', false, 'path to optional model data, passed to template, in json format'),
57
- Option('-l, --lang [lang]', false, 'optional language. Language data must be in directories configured in intl module. If none provided, default language is used')
58
- ], RenderTemplateCommand);
59
- export { RenderTemplateCommand };
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Templates } from './../index.js';
11
+ import { Argument, CliCommand, Command, Option } from '@spinajs/cli';
12
+ import { DI } from '@spinajs/di';
13
+ import * as path from 'path';
14
+ import * as fs from 'fs';
15
+ import { Logger, Log } from '@spinajs/log-common';
16
+ let RenderTemplateCommand = class RenderTemplateCommand extends CliCommand {
17
+ async execute(template, options) {
18
+ this.Log.trace(`Rendering ${template}, options: ${JSON.stringify(options)}`);
19
+ try {
20
+ const templates = await DI.resolve(Templates);
21
+ let model = {};
22
+ if (options.model && fs.existsSync(options.model)) {
23
+ this.Log.trace(`Found model file at ${options.model}, trying to load model data ... `);
24
+ const mText = fs.readFileSync(options.model, { encoding: 'utf-8' });
25
+ model = JSON.parse(mText);
26
+ }
27
+ if (options && options.file) {
28
+ this.Log.trace(`Rendering template to file ${options.file} ...`);
29
+ const dir = path.dirname(options.file);
30
+ if (!fs.existsSync(dir)) {
31
+ this.Log.trace(`Directory ${dir} not exits, creating ...`);
32
+ fs.mkdirSync(dir, { recursive: true });
33
+ }
34
+ await templates.renderToFile(template, model, options.file, options.lang);
35
+ this.Log.success(`Rendering template ${template} to file ${options.file} succeded !`);
36
+ return;
37
+ }
38
+ const result = await templates.render(template, model, options.lang);
39
+ this.Log.success(`Rendering template ${template} succeded !`);
40
+ // print out to console in raw format
41
+ console.log(result);
42
+ }
43
+ catch (err) {
44
+ this.Log.error(`Cannot render template ${template}, reason: ${err.message}, stack: ${err.stack}`);
45
+ }
46
+ }
47
+ };
48
+ __decorate([
49
+ Logger('templates'),
50
+ __metadata("design:type", Log)
51
+ ], RenderTemplateCommand.prototype, "Log", void 0);
52
+ RenderTemplateCommand = __decorate([
53
+ Command('template-render', 'Renders template, usefull for template testing'),
54
+ Argument('template', 'template path, must be in one of directory provided in configs'),
55
+ Option('-f, --file [file]', false, 'path for file, where parsing result will be saved'),
56
+ Option('-m, --model [model]', false, 'path to optional model data, passed to template, in json format'),
57
+ Option('-l, --lang [lang]', false, 'optional language. Language data must be in directories configured in intl module. If none provided, default language is used')
58
+ ], RenderTemplateCommand);
59
+ export { RenderTemplateCommand };
60
60
  //# sourceMappingURL=render.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/cli/render.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,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EAAE,KAAK,EAAE,iEAAiE,CAAC;IACvG,MAAM,CAAC,mBAAmB,EAAE,KAAK,EAAE,+HAA+H,CAAC;GACvJ,qBAAqB,CA4CjC"}
@@ -1,10 +1,10 @@
1
- declare const templates: {
2
- system: {
3
- dirs: {
4
- templates: string[];
5
- cli: string[];
6
- };
7
- };
8
- };
9
- export default templates;
1
+ declare const templates: {
2
+ system: {
3
+ dirs: {
4
+ templates: string[];
5
+ cli: string[];
6
+ };
7
+ };
8
+ };
9
+ export default templates;
10
10
  //# sourceMappingURL=templates.d.ts.map
@@ -1,14 +1,14 @@
1
- import { join, normalize, resolve } from 'path';
2
- function dir(path) {
3
- return resolve(normalize(join(process.cwd(), path)));
4
- }
5
- const templates = {
6
- system: {
7
- dirs: {
8
- templates: [dir('./../templates')],
9
- cli: [dir('./../cli')],
10
- },
11
- },
12
- };
13
- export default templates;
1
+ import { join, normalize, resolve } from 'path';
2
+ function dir(path) {
3
+ return resolve(normalize(join(process.cwd(), path)));
4
+ }
5
+ const templates = {
6
+ system: {
7
+ dirs: {
8
+ templates: [dir('./../templates')],
9
+ cli: [dir('./../cli')],
10
+ },
11
+ },
12
+ };
13
+ export default templates;
14
14
  //# sourceMappingURL=templates.js.map
@@ -1,15 +1,15 @@
1
- import { AsyncService } from '@spinajs/di';
2
- import { Log } from '@spinajs/log';
3
- import { TemplateRenderer } from './interfaces.js';
4
- export * from './interfaces.js';
5
- /**
6
- * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
7
- */
8
- export declare class Templates extends AsyncService {
9
- protected Log: Log;
10
- protected Renderers: Map<string, TemplateRenderer>;
11
- getRendererFor(extname: string): TemplateRenderer;
12
- render(template: string, model: unknown, language?: string): Promise<string>;
13
- renderToFile(template: string, model: unknown, filePath: string, language?: string): Promise<void>;
14
- }
1
+ import { AsyncService } from '@spinajs/di';
2
+ import { Log } from '@spinajs/log';
3
+ import { TemplateRenderer } from './interfaces.js';
4
+ export * from './interfaces.js';
5
+ /**
6
+ * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
7
+ */
8
+ export declare class Templates extends AsyncService {
9
+ protected Log: Log;
10
+ protected Renderers: Map<string, TemplateRenderer>;
11
+ getRendererFor(extname: string): TemplateRenderer;
12
+ render(template: string, model: unknown, language?: string): Promise<string>;
13
+ renderToFile(template: string, model: unknown, filePath: string, language?: string): Promise<void>;
14
+ }
15
15
  //# sourceMappingURL=index.d.ts.map
package/lib/mjs/index.js CHANGED
@@ -1,53 +1,53 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { InvalidOperation } from '@spinajs/exceptions';
11
- import { AsyncService, Inject, Autoinject } from '@spinajs/di';
12
- import { Log, Logger } from '@spinajs/log';
13
- import { TemplateRenderer } from './interfaces.js';
14
- import { extname } from 'path';
15
- import { Intl } from '@spinajs/intl';
16
- export * from './interfaces.js';
17
- /**
18
- * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
19
- */
20
- let Templates = class Templates extends AsyncService {
21
- getRendererFor(extname) {
22
- return this.Renderers.get(extname);
23
- }
24
- async render(template, model, language) {
25
- const extension = extname(template);
26
- if (!this.Renderers.has(extension)) {
27
- throw new InvalidOperation(`No renderer for file ${template} with extension ${extension}`);
28
- }
29
- return await this.Renderers.get(extension).render(template, model, language);
30
- }
31
- async renderToFile(template, model, filePath, language) {
32
- const extension = extname(template);
33
- if (!this.Renderers.has(extension)) {
34
- throw new InvalidOperation(`No renderer for file ${template} with extension ${extension}`);
35
- }
36
- return await this.Renderers.get(extension).renderToFile(template, model, filePath, language);
37
- }
38
- };
39
- __decorate([
40
- Logger('templates'),
41
- __metadata("design:type", Log)
42
- ], Templates.prototype, "Log", void 0);
43
- __decorate([
44
- Autoinject(TemplateRenderer, {
45
- mapFunc: (x) => x.ServiceName,
46
- }),
47
- __metadata("design:type", Map)
48
- ], Templates.prototype, "Renderers", void 0);
49
- Templates = __decorate([
50
- Inject(Intl)
51
- ], Templates);
52
- export { Templates };
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { InvalidOperation } from '@spinajs/exceptions';
11
+ import { AsyncService, Inject, Autoinject } from '@spinajs/di';
12
+ import { Log, Logger } from '@spinajs/log';
13
+ import { TemplateRenderer } from './interfaces.js';
14
+ import { extname } from 'path';
15
+ import { Intl } from '@spinajs/intl';
16
+ export * from './interfaces.js';
17
+ /**
18
+ * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
19
+ */
20
+ let Templates = class Templates extends AsyncService {
21
+ getRendererFor(extname) {
22
+ return this.Renderers.get(extname);
23
+ }
24
+ async render(template, model, language) {
25
+ const extension = extname(template);
26
+ if (!this.Renderers.has(extension)) {
27
+ throw new InvalidOperation(`No renderer for file ${template} with extension ${extension}`);
28
+ }
29
+ return await this.Renderers.get(extension).render(template, model, language);
30
+ }
31
+ async renderToFile(template, model, filePath, language) {
32
+ const extension = extname(template);
33
+ if (!this.Renderers.has(extension)) {
34
+ throw new InvalidOperation(`No renderer for file ${template} with extension ${extension}`);
35
+ }
36
+ return await this.Renderers.get(extension).renderToFile(template, model, filePath, language);
37
+ }
38
+ };
39
+ __decorate([
40
+ Logger('templates'),
41
+ __metadata("design:type", Log)
42
+ ], Templates.prototype, "Log", void 0);
43
+ __decorate([
44
+ Autoinject(TemplateRenderer, {
45
+ mapFunc: (x) => x.ServiceName,
46
+ }),
47
+ __metadata("design:type", Map)
48
+ ], Templates.prototype, "Renderers", void 0);
49
+ Templates = __decorate([
50
+ Inject(Intl)
51
+ ], Templates);
52
+ export { Templates };
53
53
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAEhC;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,YAAY;IASlC,cAAc,CAAC,OAAe;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAG,KAAc,EAAE,QAAiB;QACtE,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpC,I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AAQ,CAAC,CAAC;IAC/F,CAAC;CACF,CAAA;AA5BW;IADT,MAAM,CAAC,WAAW,CAAC;8BACL,GAAG;sCAAC;AAKT;IAHT,UAAU,CAAC,gBAAgB,EAAE;QAC5B,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW;KAC9B,CAAC;8BACmB,GAAG;4CAA2B;AAPxC,SAAS;IADrB,MAAM,CAAC,IAAI,CAAC;GACA,SAAS,CA8BrB"}
@@ -1,21 +1,21 @@
1
- import { IMappableService } from '@spinajs/di';
2
- import { AsyncService } from '@spinajs/di';
3
- import { Log } from '@spinajs/log';
4
- export declare abstract class TemplateRenderer extends AsyncService implements IMappableService {
5
- protected Log: Log;
6
- protected TemplatePaths: string[];
7
- protected TemplateFiles: Map<string, string[]>;
8
- abstract get Type(): string;
9
- abstract get Extension(): string;
10
- get ServiceName(): string;
11
- abstract render(templatePath: string, model: unknown, language?: string): Promise<string>;
12
- abstract renderToFile(templatePath: string, model: unknown, filePath: string, language?: string): Promise<void>;
13
- /**
14
- * Function used for precompiling templates at load time. Not all template engines can support it, leave it empty if so.
15
- *
16
- * @param templateName - template name
17
- * @param path - template full path
18
- */
19
- protected abstract compile(templateName: string, path: string): Promise<void>;
20
- }
1
+ import { IMappableService } from '@spinajs/di';
2
+ import { AsyncService } from '@spinajs/di';
3
+ import { Log } from '@spinajs/log';
4
+ export declare abstract class TemplateRenderer extends AsyncService implements IMappableService {
5
+ protected Log: Log;
6
+ protected TemplatePaths: string[];
7
+ protected TemplateFiles: Map<string, string[]>;
8
+ abstract get Type(): string;
9
+ abstract get Extension(): string;
10
+ get ServiceName(): string;
11
+ abstract render(templatePath: string, model: unknown, language?: string): Promise<string>;
12
+ abstract renderToFile(templatePath: string, model: unknown, filePath: string, language?: string): Promise<void>;
13
+ /**
14
+ * Function used for precompiling templates at load time. Not all template engines can support it, leave it empty if so.
15
+ *
16
+ * @param templateName - template name
17
+ * @param path - template full path
18
+ */
19
+ protected abstract compile(templateName: string, path: string): Promise<void>;
20
+ }
21
21
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1,31 +1,31 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Config } from '@spinajs/configuration';
11
- import { AsyncService } from '@spinajs/di';
12
- import { Logger, Log } from '@spinajs/log';
13
- export class TemplateRenderer extends AsyncService {
14
- constructor() {
15
- super(...arguments);
16
- this.TemplateFiles = new Map();
17
- }
18
- get ServiceName() {
19
- // we map this service by extension
20
- return this.Extension;
21
- }
22
- }
23
- __decorate([
24
- Logger('renderer'),
25
- __metadata("design:type", Log)
26
- ], TemplateRenderer.prototype, "Log", void 0);
27
- __decorate([
28
- Config('system.dirs.templates', { defaultValue: [] }),
29
- __metadata("design:type", Array)
30
- ], TemplateRenderer.prototype, "TemplatePaths", void 0);
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Config } from '@spinajs/configuration';
11
+ import { AsyncService } from '@spinajs/di';
12
+ import { Logger, Log } from '@spinajs/log';
13
+ export class TemplateRenderer extends AsyncService {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.TemplateFiles = new Map();
17
+ }
18
+ get ServiceName() {
19
+ // we map this service by extension
20
+ return this.Extension;
21
+ }
22
+ }
23
+ __decorate([
24
+ Logger('renderer'),
25
+ __metadata("design:type", Log)
26
+ ], TemplateRenderer.prototype, "Log", void 0);
27
+ __decorate([
28
+ Config('system.dirs.templates', { defaultValue: [] }),
29
+ __metadata("design:type", Array)
30
+ ], TemplateRenderer.prototype, "TemplatePaths", void 0);
31
31
  //# sourceMappingURL=interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAG3C,MAAM,OAAgB,gBAAiB,SAAQ,YAAY;IAA3D;;QAOY,kBAAa,GAA0B,IAAI,GAAG,EAAoB,CAAC;IAqB/E,CAAC;IAfC,IAAW,WAAW;QACpB,mCAAmC;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CAYF;AA3BC;IAAC,MAAM,CAAC,UAAU,CAAC;8BACJ,GAAG;6CAAC;AAEnB;IAAC,MAAM,CAAC,uBAAuB,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;;uDACpB"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAG3C,MAAM,OAAgB,gBAAiB,SAAQ,YAAY;IAA3D;;QAOY,kBAAa,GAA0B,IAAI,GAAG,EAAoB,CAAC;IAqB/E,CAAC;IAfC,IAAW,WAAW;QACpB,mCAAmC;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CAYF;AA1BW;IADT,MAAM,CAAC,UAAU,CAAC;8BACJ,GAAG;6CAAC;AAGT;IADT,MAAM,CAAC,uBAAuB,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;;uDACpB"}