@oicana/node 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
@@ -8,21 +8,18 @@ import type { BlobWithMetadata } from './inputs/index.js';
8
8
  */
9
9
  export declare class Template {
10
10
  private readonly template;
11
- private defaultCompilationMode;
12
11
  /**
13
- * Register a template with the given name and template file
14
- * @param name of the template
12
+ * Register a template with the given template file
15
13
  * @param template - the packed Oicana template file
16
14
  */
17
- constructor(name: string, template: Uint8Array);
15
+ constructor(template: Uint8Array);
18
16
  /**
19
- * Register a template with the given name, template file, and inputs
20
- * @param name of the template
17
+ * Register a template with the given template file and inputs
21
18
  * @param template - the packed Oicana template file
22
- * @param jsonInputs for the initial rendering to warm up the cache
23
- * @param blobInputs for the initial rendering to warm up the cache
19
+ * @param jsonInputs for the initial compilation to warm up the cache
20
+ * @param blobInputs for the initial compilation to warm up the cache
24
21
  */
25
- constructor(name: string, template: Uint8Array, jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>);
22
+ constructor(template: Uint8Array, jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>);
26
23
  /**
27
24
  * Compile the template to a PDF file without any inputs in production mode
28
25
  */
@@ -37,18 +34,17 @@ export declare class Template {
37
34
  * Compile the template with the given inputs
38
35
  * @param jsonInputs
39
36
  * @param blobInputs
40
- * @param exportFormat
37
+ * @param exportOptions
41
38
  */
42
- compile(jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>, exportFormat: ExportFormat): Uint8Array;
39
+ compile(jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>, exportOptions: ExportFormat): Uint8Array;
43
40
  /**
44
- * Get the default compilation mode of this template
45
- */
46
- defaultMode(): CompilationMode;
47
- /**
48
- * Set the default compilation mode of this template
49
- * @param compilationMode to use as default when compiling this template
41
+ * Compile the template with the given inputs
42
+ * @param jsonInputs
43
+ * @param blobInputs
44
+ * @param exportOptions
45
+ * @param compilationOptions
50
46
  */
51
- setDefaultMode(compilationMode: CompilationMode): void;
47
+ compile(jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>, exportOptions: ExportFormat, compilationOptions: CompilationMode): Uint8Array;
52
48
  private convertBlobWithMetadata;
53
49
  private mapCompilationMode;
54
50
  }
package/dist/Template.js CHANGED
@@ -1,4 +1,5 @@
1
- import { compileTemplate, registerTemplate, exportDocument } from '@oicana/node-native';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { compileTemplate, exportDocument, registerTemplate, removeDocument, } from '@oicana/node-native';
2
3
  import { CompilationMode } from './CompilationMode.js';
3
4
  /**
4
5
  * A template
@@ -7,44 +8,33 @@ import { CompilationMode } from './CompilationMode.js';
7
8
  */
8
9
  export class Template {
9
10
  template;
10
- defaultCompilationMode;
11
11
  /**
12
- * Register a template with the given name, template file, and inputs
13
- * @param name of the template
12
+ * Register a template with the given template file and inputs
14
13
  * @param template - the packed Oicana template file
15
- * @param jsonInputs for the initial rendering to warm up the cache
16
- * @param blobInputs for the initial rendering to warm up the cache
17
- * @param compilation mode for the initial rendering to warm up the cache
14
+ * @param jsonInputs for the initial compilation to warm up the cache (defaults to empty map)
15
+ * @param blobInputs for the initial compilation to warm up the cache (defaults to empty map)
16
+ * @param compilationOptions for the initial compilation to warm up the cache (defaults to Development)
18
17
  */
19
- constructor(name, template, jsonInputs, blobInputs, compilationMode) {
20
- this.template = name;
21
- this.defaultCompilationMode = CompilationMode.Production;
22
- registerTemplate(this.template, template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), this.mapCompilationMode(compilationMode ?? CompilationMode.Development));
18
+ constructor(template, jsonInputs, blobInputs, compilationOptions) {
19
+ this.template = randomUUID();
20
+ registerTemplate(this.template, template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), this.mapCompilationMode(compilationOptions ?? CompilationMode.Development));
23
21
  }
24
22
  /**
25
23
  * Compile the template with the given inputs
26
- * @param jsonInputs
27
- * @param blobInputs
28
- * @param exportFormat
29
- * @param compilationMode
24
+ * @param jsonInputs - JSON inputs for the template (defaults to empty map)
25
+ * @param blobInputs - Blob inputs for the template (defaults to empty map)
26
+ * @param exportOptions - Export format specification (defaults to PDF)
27
+ * @param compilationOptions - Compilation mode (defaults to Production)
30
28
  */
31
- compile(jsonInputs, blobInputs, exportFormat, compilationMode) {
32
- const format = exportFormat ?? { format: 'pdf' };
33
- const document = compileTemplate(this.template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), this.mapCompilationMode(compilationMode ?? CompilationMode.Production));
34
- return exportDocument(document, JSON.stringify(format));
35
- }
36
- /**
37
- * Get the default compilation mode of this template
38
- */
39
- defaultMode() {
40
- return this.defaultCompilationMode;
41
- }
42
- /**
43
- * Set the default compilation mode of this template
44
- * @param compilationMode to use as default when compiling this template
45
- */
46
- setDefaultMode(compilationMode) {
47
- this.defaultCompilationMode = compilationMode;
29
+ compile(jsonInputs, blobInputs, exportOptions, compilationOptions) {
30
+ const format = exportOptions ?? { format: 'pdf' };
31
+ const document = compileTemplate(this.template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), this.mapCompilationMode(compilationOptions ?? CompilationMode.Production));
32
+ try {
33
+ return exportDocument(document, JSON.stringify(format));
34
+ }
35
+ finally {
36
+ removeDocument(document);
37
+ }
48
38
  }
49
39
  convertBlobWithMetadata(blobInputs) {
50
40
  return Object.fromEntries(Array.from(blobInputs.entries(), ([key, value]) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEf,gBAAgB,EAChB,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;;;GAIG;AACH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AAC;IACJ,CAAC;IAEO,kBAAkB,CAAC,IAAqB;QAC9C,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,eAAe,CAAC,WAAW;gBAC9B,iDAAyC;YAC3C,KAAK,eAAe,CAAC,UAAU;gBAC7B,gDAAwC;QAC5C,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oicana/node",
3
3
  "author": "Oicana <hello@oicana.com>",
4
- "version": "0.1.0-alpha.3",
4
+ "version": "0.1.0-alpha.5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "readme": "README.md",
@@ -22,7 +22,7 @@
22
22
  "lint": "biome ci"
23
23
  },
24
24
  "dependencies": {
25
- "@oicana/node-native": "0.1.0-alpha.3"
25
+ "@oicana/node-native": "0.1.0-alpha.5"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@biomejs/biome": "2.2.4",
package/src/Template.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from 'node:crypto';
1
2
  import {
2
3
  type BlobWithMetadata as BlobWithMetadataNative,
3
4
  compileTemplate,
@@ -17,46 +18,39 @@ import type { BlobWithMetadata } from './inputs/index.js';
17
18
  */
18
19
  export class Template {
19
20
  private readonly template: string;
20
- private defaultCompilationMode: CompilationMode;
21
21
 
22
22
  /**
23
- * Register a template with the given name and template file
24
- * @param name of the template
23
+ * Register a template with the given template file
25
24
  * @param template - the packed Oicana template file
26
25
  */
27
- public constructor(name: string, template: Uint8Array);
26
+ public constructor(template: Uint8Array);
28
27
 
29
28
  /**
30
- * Register a template with the given name, template file, and inputs
31
- * @param name of the template
29
+ * Register a template with the given template file and inputs
32
30
  * @param template - the packed Oicana template file
33
- * @param jsonInputs for the initial rendering to warm up the cache
34
- * @param blobInputs for the initial rendering to warm up the cache
31
+ * @param jsonInputs for the initial compilation to warm up the cache
32
+ * @param blobInputs for the initial compilation to warm up the cache
35
33
  */
36
34
  public constructor(
37
- name: string,
38
35
  template: Uint8Array,
39
36
  jsonInputs: Map<string, string>,
40
37
  blobInputs: Map<string, BlobWithMetadata>,
41
38
  );
42
39
 
43
40
  /**
44
- * Register a template with the given name, template file, and inputs
45
- * @param name of the template
41
+ * Register a template with the given template file and inputs
46
42
  * @param template - the packed Oicana template file
47
- * @param jsonInputs for the initial rendering to warm up the cache
48
- * @param blobInputs for the initial rendering to warm up the cache
49
- * @param compilation mode for the initial rendering to warm up the cache
43
+ * @param jsonInputs for the initial compilation to warm up the cache (defaults to empty map)
44
+ * @param blobInputs for the initial compilation to warm up the cache (defaults to empty map)
45
+ * @param compilationOptions for the initial compilation to warm up the cache (defaults to Development)
50
46
  */
51
47
  public constructor(
52
- name: string,
53
48
  template: Uint8Array,
54
49
  jsonInputs?: Map<string, string>,
55
50
  blobInputs?: Map<string, BlobWithMetadata>,
56
- compilationMode?: CompilationMode,
51
+ compilationOptions?: CompilationMode,
57
52
  ) {
58
- this.template = name;
59
- this.defaultCompilationMode = CompilationMode.Production;
53
+ this.template = randomUUID();
60
54
 
61
55
  registerTemplate(
62
56
  this.template,
@@ -65,7 +59,9 @@ export class Template {
65
59
  this.convertBlobWithMetadata(
66
60
  blobInputs ?? new Map<string, BlobWithMetadata>(),
67
61
  ),
68
- this.mapCompilationMode(compilationMode ?? CompilationMode.Development),
62
+ this.mapCompilationMode(
63
+ compilationOptions ?? CompilationMode.Development,
64
+ ),
69
65
  );
70
66
  }
71
67
 
@@ -88,28 +84,42 @@ export class Template {
88
84
  * Compile the template with the given inputs
89
85
  * @param jsonInputs
90
86
  * @param blobInputs
91
- * @param exportFormat
87
+ * @param exportOptions
92
88
  */
93
89
  public compile(
94
90
  jsonInputs: Map<string, string>,
95
91
  blobInputs: Map<string, BlobWithMetadata>,
96
- exportFormat: ExportFormat,
92
+ exportOptions: ExportFormat,
97
93
  ): Uint8Array;
98
94
 
99
95
  /**
100
96
  * Compile the template with the given inputs
101
97
  * @param jsonInputs
102
98
  * @param blobInputs
103
- * @param exportFormat
104
- * @param compilationMode
99
+ * @param exportOptions
100
+ * @param compilationOptions
101
+ */
102
+ public compile(
103
+ jsonInputs: Map<string, string>,
104
+ blobInputs: Map<string, BlobWithMetadata>,
105
+ exportOptions: ExportFormat,
106
+ compilationOptions: CompilationMode,
107
+ ): Uint8Array;
108
+
109
+ /**
110
+ * Compile the template with the given inputs
111
+ * @param jsonInputs - JSON inputs for the template (defaults to empty map)
112
+ * @param blobInputs - Blob inputs for the template (defaults to empty map)
113
+ * @param exportOptions - Export format specification (defaults to PDF)
114
+ * @param compilationOptions - Compilation mode (defaults to Production)
105
115
  */
106
116
  public compile(
107
117
  jsonInputs?: Map<string, string>,
108
118
  blobInputs?: Map<string, BlobWithMetadata>,
109
- exportFormat?: ExportFormat,
110
- compilationMode?: CompilationMode,
119
+ exportOptions?: ExportFormat,
120
+ compilationOptions?: CompilationMode,
111
121
  ): Uint8Array {
112
- const format: ExportFormat = exportFormat ?? { format: 'pdf' };
122
+ const format: ExportFormat = exportOptions ?? { format: 'pdf' };
113
123
 
114
124
  const document = compileTemplate(
115
125
  this.template,
@@ -117,7 +127,7 @@ export class Template {
117
127
  this.convertBlobWithMetadata(
118
128
  blobInputs ?? new Map<string, BlobWithMetadata>(),
119
129
  ),
120
- this.mapCompilationMode(compilationMode ?? CompilationMode.Production),
130
+ this.mapCompilationMode(compilationOptions ?? CompilationMode.Production),
121
131
  );
122
132
  try {
123
133
  return exportDocument(document, JSON.stringify(format));
@@ -126,21 +136,6 @@ export class Template {
126
136
  }
127
137
  }
128
138
 
129
- /**
130
- * Get the default compilation mode of this template
131
- */
132
- public defaultMode(): CompilationMode {
133
- return this.defaultCompilationMode;
134
- }
135
-
136
- /**
137
- * Set the default compilation mode of this template
138
- * @param compilationMode to use as default when compiling this template
139
- */
140
- public setDefaultMode(compilationMode: CompilationMode) {
141
- this.defaultCompilationMode = compilationMode;
142
- }
143
-
144
139
  private convertBlobWithMetadata(
145
140
  blobInputs: Map<string, BlobWithMetadata>,
146
141
  ): Record<string, BlobWithMetadataNative> {