@tstdl/base 0.83.2 → 0.83.3

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/.eslintrc.cjs CHANGED
@@ -35,6 +35,7 @@ module.exports = {
35
35
  '@typescript-eslint/explicit-module-boundary-types': 'off',
36
36
  '@typescript-eslint/indent': 'off',
37
37
  '@typescript-eslint/init-declarations': 'off',
38
+ '@typescript-eslint/lines-around-comment': 'off',
38
39
  '@typescript-eslint/lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
39
40
  '@typescript-eslint/method-signature-style': 'off',
40
41
  '@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true, ignoreVoidOperator: true }],
@@ -93,7 +94,7 @@ module.exports = {
93
94
  'function-paren-newline': ['warn', 'consistent'],
94
95
  'generator-star-spacing': ['off', { before: false, after: true }],
95
96
  'id-length': 'off',
96
- 'indent': ['error', 2, { SwitchCase: 1 }],
97
+ 'indent': 'off',
97
98
  'init-declarations': 'off',
98
99
  'line-comment-position': 'off',
99
100
  'linebreak-style': ['error', 'unix'],
@@ -183,9 +184,11 @@ module.exports = {
183
184
  'protected-static-field',
184
185
  'public-static-field',
185
186
 
187
+ /*
186
188
  'private-decorated-field',
187
189
  'protected-decorated-field',
188
190
  'public-decorated-field',
191
+ */
189
192
 
190
193
  '#private-instance-field',
191
194
  'private-instance-field',
@@ -204,7 +207,7 @@ module.exports = {
204
207
  'instance-field',
205
208
  'abstract-field',
206
209
 
207
- 'decorated-field',
210
+ // 'decorated-field',
208
211
 
209
212
  'field',
210
213
 
@@ -214,9 +217,11 @@ module.exports = {
214
217
  'protected-static-get',
215
218
  'public-static-get',
216
219
 
220
+ /*
217
221
  'private-decorated-get',
218
222
  'protected-decorated-get',
219
223
  'public-decorated-get',
224
+ */
220
225
 
221
226
  '#private-instance-get',
222
227
  'private-instance-get',
@@ -235,7 +240,7 @@ module.exports = {
235
240
  'instance-get',
236
241
  'abstract-get',
237
242
 
238
- 'decorated-get',
243
+ // 'decorated-get',
239
244
 
240
245
  'get',
241
246
 
@@ -245,9 +250,11 @@ module.exports = {
245
250
  'protected-static-set',
246
251
  'public-static-set',
247
252
 
253
+ /*
248
254
  'private-decorated-set',
249
255
  'protected-decorated-set',
250
256
  'public-decorated-set',
257
+ */
251
258
 
252
259
  '#private-instance-set',
253
260
  'private-instance-set',
@@ -266,7 +273,7 @@ module.exports = {
266
273
  'instance-set',
267
274
  'abstract-set',
268
275
 
269
- 'decorated-set',
276
+ // 'decorated-set',
270
277
 
271
278
  'set',
272
279
 
@@ -286,9 +293,11 @@ module.exports = {
286
293
  'private-static-method',
287
294
  '#private-static-method',
288
295
 
296
+ /*
289
297
  'public-decorated-method',
290
298
  'protected-decorated-method',
291
299
  'private-decorated-method',
300
+ */
292
301
 
293
302
  'public-instance-method',
294
303
  'protected-instance-method',
@@ -307,7 +316,7 @@ module.exports = {
307
316
  'instance-method',
308
317
  'abstract-method',
309
318
 
310
- 'decorated-method',
319
+ // 'decorated-method',
311
320
 
312
321
  'method'
313
322
  ]
@@ -1,2 +1,2 @@
1
- declare const template: import("../../../mail/index.js").MailTemplate;
1
+ declare const template: import("../../../mail/index.js").MailTemplate<object>;
2
2
  export default template;
@@ -1,2 +1,2 @@
1
- declare const template: import("../../../pdf/pdf.service.js").PdfTemplate;
1
+ declare const template: import("../../../pdf/pdf.service.js").PdfTemplate<any>;
2
2
  export default template;
@@ -1,2 +1,2 @@
1
- export declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any>;
1
+ export declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any, any>;
2
2
  export default template;
@@ -1,2 +1,2 @@
1
- declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any>;
1
+ declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any, any>;
2
2
  export default template;
@@ -14,5 +14,5 @@ export declare class MailService {
14
14
  send(mailData: MailData): Promise<MailSendResult>;
15
15
  /** @deprecated internal */
16
16
  send(mailData: MailData, templateName?: string): Promise<MailSendResult>;
17
- sendTemplate(keyOrTemplate: string | MailTemplate, mailData: TypedOmit<MailData, 'content' | 'subject'>, templateContext?: object): Promise<MailSendResult>;
17
+ sendTemplate<Context extends object>(keyOrTemplate: string | MailTemplate<Context>, mailData: TypedOmit<MailData, 'content' | 'subject'>, templateContext?: Context): Promise<MailSendResult>;
18
18
  }
@@ -1,11 +1,11 @@
1
1
  import type { Template, TemplateField } from '../../templates/template.model.js';
2
- export type MailTemplate = Template<{
2
+ export type MailTemplate<Context extends object = any> = Template<{
3
3
  subject: false;
4
4
  html: false;
5
5
  text: false;
6
- }, undefined>;
7
- export declare function mailTemplate(name: string, fields: {
6
+ }, undefined, Context>;
7
+ export declare function mailTemplate<Context extends object>(name: string, fields: {
8
8
  subject?: TemplateField;
9
9
  html?: TemplateField;
10
10
  text?: TemplateField;
11
- }): MailTemplate;
11
+ }): MailTemplate<Context>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.83.2",
3
+ "version": "0.83.3",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -45,11 +45,11 @@ export declare class PdfRenderOptions {
45
45
  timeout?: number;
46
46
  }
47
47
  export type PdfTemplateOptions = PdfRenderOptions;
48
- export declare class PdfTemplate extends Template<{
48
+ export declare class PdfTemplate<Context extends object = any> extends Template<{
49
49
  header: false;
50
50
  body: true;
51
51
  footer: false;
52
- }, PdfRenderOptions> {
52
+ }, PdfRenderOptions, Context> {
53
53
  options?: PdfTemplateOptions;
54
54
  }
55
55
  export type PdfServiceOptions = {
@@ -101,7 +101,7 @@ export declare class PdfService implements AsyncDisposable, AfterResolve, Inject
101
101
  * @param options additional options, overwrites options specified in template
102
102
  * @returns pdf bytes
103
103
  */
104
- renderTemplateStream(keyOrTemplate: string | PdfTemplate, templateContext?: object, options?: PdfRenderOptions): ReadableStream<Uint8Array>;
104
+ renderTemplateStream<Context extends object>(keyOrTemplate: string | PdfTemplate<Context>, templateContext?: Context, options?: PdfRenderOptions): ReadableStream<Uint8Array>;
105
105
  /**
106
106
  * Renders a template to pdf
107
107
  * @param key template key
@@ -1,4 +1,6 @@
1
1
  import type { PickBy, Record, SimplifyObject } from '../types.js';
2
+ export type TemplateContext<T extends Template> = T[typeof templateContext];
3
+ export declare const templateContext: unique symbol;
2
4
  export declare class TemplateField<Resolver extends string = string, Renderer extends string = string, Options = any> {
3
5
  resolver: Resolver;
4
6
  renderer: Renderer;
@@ -9,7 +11,8 @@ export type TemplateFields<Fields extends Record<string, boolean>, Resolver exte
9
11
  } & {
10
12
  [P in keyof PickBy<Fields, false>]?: TemplateField<Resolver, Renderer, Options>;
11
13
  }>;
12
- export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any> {
14
+ export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any, Context extends object = any> {
15
+ readonly [templateContext]?: Context;
13
16
  /** name of template */
14
17
  name: string;
15
18
  fields: TemplateFields<Fields>;
@@ -20,7 +20,8 @@ var template_model_exports = {};
20
20
  __export(template_model_exports, {
21
21
  Template: () => Template,
22
22
  TemplateField: () => TemplateField,
23
- simpleTemplate: () => simpleTemplate
23
+ simpleTemplate: () => simpleTemplate,
24
+ templateContext: () => templateContext
24
25
  });
25
26
  module.exports = __toCommonJS(template_model_exports);
26
27
  var import_schema = require("../schema/index.js");
@@ -38,6 +39,7 @@ var __metadata = function(k, v) {
38
39
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
39
40
  return Reflect.metadata(k, v);
40
41
  };
42
+ const templateContext = Symbol("templateData");
41
43
  let TemplateField = class TemplateField2 {
42
44
  resolver;
43
45
  renderer;
@@ -1,7 +1,7 @@
1
1
  import type { Record } from '../types.js';
2
2
  import { TemplateRendererProvider } from './template-renderer.provider.js';
3
3
  import { TemplateResolverProvider } from './template-resolver.provider.js';
4
- import type { Template } from './template.model.js';
4
+ import type { Template, TemplateContext } from './template.model.js';
5
5
  import { TemplateProvider } from './template.provider.js';
6
6
  export type TemplateServiceRenderResult<T extends Template = Template> = {
7
7
  name: string;
@@ -14,5 +14,5 @@ export declare class TemplateService {
14
14
  private readonly templateResolverProvider;
15
15
  constructor(templateProvider: TemplateProvider | undefined, templateRendererProvider: TemplateRendererProvider, templateResolverProvider: TemplateResolverProvider);
16
16
  get<T extends Template = Template>(key: string): Promise<T>;
17
- render<T extends Template = Template>(keyOrTemplate: string | T, templateContext?: object): Promise<TemplateServiceRenderResult<T>>;
17
+ render<T extends Template = Template>(keyOrTemplate: string | T, templateContext?: TemplateContext<T>): Promise<TemplateServiceRenderResult<T>>;
18
18
  }