@oicana/node 0.1.0-alpha.5 → 0.1.0-alpha.7
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/dist/Template.d.ts +10 -1
- package/dist/Template.js +16 -2
- package/dist/Template.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Template.ts +19 -2
- package/src/index.ts +4 -0
package/dist/Template.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { BlobWithMetadata } from './inputs/index.js';
|
|
|
6
6
|
*
|
|
7
7
|
* The zip file is loaded during the instance creation and cached afterward.
|
|
8
8
|
*/
|
|
9
|
-
export declare class Template {
|
|
9
|
+
export declare class Template implements Disposable {
|
|
10
10
|
private readonly template;
|
|
11
11
|
/**
|
|
12
12
|
* Register a template with the given template file
|
|
@@ -45,6 +45,15 @@ export declare class Template {
|
|
|
45
45
|
* @param compilationOptions
|
|
46
46
|
*/
|
|
47
47
|
compile(jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>, exportOptions: ExportFormat, compilationOptions: CompilationMode): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* Release resources associated with this template.
|
|
50
|
+
* After calling dispose(), this template instance should not be used.
|
|
51
|
+
*/
|
|
52
|
+
dispose(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Enables use with the `using` keyword for automatic resource cleanup.
|
|
55
|
+
*/
|
|
56
|
+
[Symbol.dispose](): void;
|
|
48
57
|
private convertBlobWithMetadata;
|
|
49
58
|
private mapCompilationMode;
|
|
50
59
|
}
|
package/dist/Template.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { compileTemplate, exportDocument, registerTemplate, removeDocument, } from '@oicana/node-native';
|
|
2
|
+
import { compileTemplate, exportDocument, registerTemplate, removeDocument, removeWorld, } from '@oicana/node-native';
|
|
3
3
|
import { CompilationMode } from './CompilationMode.js';
|
|
4
4
|
/**
|
|
5
5
|
* A template
|
|
@@ -30,12 +30,26 @@ export class Template {
|
|
|
30
30
|
const format = exportOptions ?? { format: 'pdf' };
|
|
31
31
|
const document = compileTemplate(this.template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), this.mapCompilationMode(compilationOptions ?? CompilationMode.Production));
|
|
32
32
|
try {
|
|
33
|
-
|
|
33
|
+
const exportedDocument = exportDocument(document, JSON.stringify(format));
|
|
34
|
+
return exportedDocument;
|
|
34
35
|
}
|
|
35
36
|
finally {
|
|
36
37
|
removeDocument(document);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Release resources associated with this template.
|
|
42
|
+
* After calling dispose(), this template instance should not be used.
|
|
43
|
+
*/
|
|
44
|
+
dispose() {
|
|
45
|
+
removeWorld(this.template);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Enables use with the `using` keyword for automatic resource cleanup.
|
|
49
|
+
*/
|
|
50
|
+
[Symbol.dispose]() {
|
|
51
|
+
this.dispose();
|
|
52
|
+
}
|
|
39
53
|
convertBlobWithMetadata(blobInputs) {
|
|
40
54
|
return Object.fromEntries(Array.from(blobInputs.entries(), ([key, value]) => {
|
|
41
55
|
const nativeValue = {
|
package/dist/Template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAEL,eAAe,EACf,cAAc,EAEd,gBAAgB,EAChB,cAAc,
|
|
1
|
+
{"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAEL,eAAe,EACf,cAAc,EAEd,gBA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CAAC;IACH,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAEO,uBAAuB,CAC7B,UAAyC;QAEzC,OAAO,MAAM,CAAC,WAAW,CACvB,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAChD,MAAM,WAAW,GAAG;gBAClB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;aACnE,CAAC;YACF,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC,CACH,CAAC;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/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
|
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.
|
|
4
|
+
"version": "0.1.0-alpha.7",
|
|
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.
|
|
25
|
+
"@oicana/node-native": "0.1.0-alpha.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@biomejs/biome": "2.2.4",
|
package/src/Template.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
CompilationMode as NativeCompilationMode,
|
|
7
7
|
registerTemplate,
|
|
8
8
|
removeDocument,
|
|
9
|
+
removeWorld,
|
|
9
10
|
} from '@oicana/node-native';
|
|
10
11
|
import { CompilationMode } from './CompilationMode.js';
|
|
11
12
|
import type { ExportFormat } from './ExportFormat.js';
|
|
@@ -16,7 +17,7 @@ import type { BlobWithMetadata } from './inputs/index.js';
|
|
|
16
17
|
*
|
|
17
18
|
* The zip file is loaded during the instance creation and cached afterward.
|
|
18
19
|
*/
|
|
19
|
-
export class Template {
|
|
20
|
+
export class Template implements Disposable {
|
|
20
21
|
private readonly template: string;
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -130,12 +131,28 @@ export class Template {
|
|
|
130
131
|
this.mapCompilationMode(compilationOptions ?? CompilationMode.Production),
|
|
131
132
|
);
|
|
132
133
|
try {
|
|
133
|
-
|
|
134
|
+
const exportedDocument = exportDocument(document, JSON.stringify(format));
|
|
135
|
+
return exportedDocument;
|
|
134
136
|
} finally {
|
|
135
137
|
removeDocument(document);
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Release resources associated with this template.
|
|
143
|
+
* After calling dispose(), this template instance should not be used.
|
|
144
|
+
*/
|
|
145
|
+
public dispose(): void {
|
|
146
|
+
removeWorld(this.template);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Enables use with the `using` keyword for automatic resource cleanup.
|
|
151
|
+
*/
|
|
152
|
+
[Symbol.dispose](): void {
|
|
153
|
+
this.dispose();
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
private convertBlobWithMetadata(
|
|
140
157
|
blobInputs: Map<string, BlobWithMetadata>,
|
|
141
158
|
): Record<string, BlobWithMetadataNative> {
|