@platforma-sdk/tengo-builder 1.17.4 → 1.17.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.
@@ -1,69 +1,17 @@
1
- import { gunzipSync, gzipSync } from 'node:zlib';
2
- import canonicalize from 'canonicalize';
3
- import {
1
+ import type {
4
2
  CompileMode,
5
3
  FullArtifactName,
6
4
  FullArtifactNameWithoutType,
5
+ } from './package';
6
+ import {
7
7
  fullNameWithoutTypeToString,
8
- parseArtefactNameAndVersion
8
+ parseArtefactNameAndVersion,
9
9
  } from './package';
10
-
11
- export interface TemplateLibData {
12
- /** i.e. @milaboratory/some-package:lib1 */
13
- name: string;
14
- /** i.e. 1.2.3 */
15
- version: string;
16
- /** full source code */
17
- src: string,
18
- }
19
-
20
- export interface TemplateSoftwareData {
21
- /** i.e. @milaboratory/mixcr:main */
22
- name: string;
23
- /** i.e. 4.2.3 */
24
- version: string;
25
- /** full contents of software dependency description */
26
- src: string,
27
- }
28
-
29
- export interface TemplateAssetData {
30
- /** i.e. @milaboratory/mixcr:main */
31
- name: string;
32
- /** i.e. 4.2.3 */
33
- version: string;
34
- /** full contents of asset dependency description */
35
- src: string,
36
- }
37
-
38
- export interface TemplateData {
39
- /** Discriminator for future use */
40
- type: 'pl.tengo-template.v2';
41
-
42
- /** i.e. @milaboratory/some-package:template */
43
- name: string;
44
- /** i.e. 1.2.3 */
45
- version: string;
46
-
47
- /**
48
- * Custom hash token of the template for deduplication purposes. Can be set with 'hash_override' compiler option.
49
- * Dangerous! Remember: great power comes with great responsibility.
50
- */
51
- hashOverride?: string;
52
-
53
- /** i.e. @milaboratory/some-package:some-lib -> normalized library source code */
54
- libs: Record<string, TemplateLibData>;
55
- /** i.e. @milaboratory/some-package:some-lib -> to nested template data */
56
- templates: Record<string, TemplateData>;
57
- /** i.e. @milaboratory/mixcr:main -> software metadata */
58
- software: Record<string, TemplateSoftwareData>;
59
- /** i.e. @milaboratory/genome:human -> asset metadata */
60
- assets: Record<string, TemplateAssetData>;
61
- /** Template source code */
62
- src: string;
63
- }
64
-
65
- const decoder = new TextDecoder();
66
- const encoder = new TextEncoder();
10
+ import type { TemplateData } from '@milaboratories/pl-model-backend';
11
+ import {
12
+ parseTemplate,
13
+ serializeTemplate,
14
+ } from '@milaboratories/pl-model-backend';
67
15
 
68
16
  export class Template {
69
17
  public readonly data: TemplateData;
@@ -73,9 +21,9 @@ export class Template {
73
21
  public readonly compileMode: CompileMode,
74
22
  public readonly fullName: FullArtifactName,
75
23
  body: {
76
- data?: TemplateData,
77
- content?: Uint8Array
78
- }
24
+ data?: TemplateData;
25
+ content?: Uint8Array;
26
+ },
79
27
  ) {
80
28
  let { data, content } = body;
81
29
  if (data === undefined && content === undefined)
@@ -83,25 +31,25 @@ export class Template {
83
31
  if (data !== undefined && content !== undefined)
84
32
  throw new Error('Both data and content are provided for template constructor');
85
33
 
86
- if (data === undefined) {
87
- data = JSON.parse(decoder.decode(gunzipSync(content!))) as TemplateData;
88
- if (data.type !== 'pl.tengo-template.v2')
89
- throw new Error('malformed template');
90
- }
91
-
92
- if (content === undefined)
93
- content = gzipSync(encoder.encode(canonicalize(data!)), { chunkSize: 256 * 1024, level: 9 });
34
+ if (data === undefined) data = parseTemplate(content!);
35
+ if (content === undefined) content = serializeTemplate(data);
94
36
 
95
37
  const nameFromData: FullArtifactNameWithoutType = parseArtefactNameAndVersion(data);
96
38
 
97
- if (nameFromData.pkg !== fullName.pkg || nameFromData.id !== fullName.id || nameFromData.version !== fullName.version)
98
- throw new Error(`Compiled template name don't match it's package and file names: ${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`);
39
+ if (
40
+ nameFromData.pkg !== fullName.pkg
41
+ || nameFromData.id !== fullName.id
42
+ || nameFromData.version !== fullName.version
43
+ )
44
+ throw new Error(
45
+ `Compiled template name don't match it's package and file names: ${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,
46
+ );
99
47
 
100
48
  this.data = data;
101
49
  this.content = content;
102
50
  }
103
51
 
104
52
  toJSON() {
105
- return { compileMode: this.compileMode, fullName: this.fullName, data: this.data }
53
+ return { compileMode: this.compileMode, fullName: this.fullName, data: this.data };
106
54
  }
107
55
  }
package/src/index.ts CHANGED
@@ -20,5 +20,5 @@ export const COMMANDS = {
20
20
  'dump:libs': Cmd5,
21
21
  'dump:software': Cmd6,
22
22
  'dump:templates': Cmd7,
23
- 'dump:tests': Cmd8
23
+ 'dump:tests': Cmd8,
24
24
  };