@distrohelena/canton-typescript-sdk 0.1.24 → 0.1.26
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/README.md +10 -5
- package/dist/daml-interface/analysis/analyzed-choice.d.ts +5 -5
- package/dist/daml-interface/analysis/analyzed-daml-type-definition.d.ts +6 -0
- package/dist/daml-interface/analysis/analyzed-daml-type-definition.js +1 -0
- package/dist/daml-interface/analysis/analyzed-daml-type.d.ts +54 -0
- package/dist/daml-interface/analysis/analyzed-daml-type.js +1 -0
- package/dist/daml-interface/analysis/analyzed-template.d.ts +3 -3
- package/dist/daml-interface/analysis/daml-interface-analyzer.d.ts +3 -1
- package/dist/daml-interface/analysis/daml-interface-analyzer.js +183 -19
- package/dist/daml-interface/emission/named-type-emitter.d.ts +41 -0
- package/dist/daml-interface/emission/named-type-emitter.js +441 -0
- package/dist/daml-interface/emission/project-emitter.d.ts +5 -1
- package/dist/daml-interface/emission/project-emitter.js +20 -3
- package/dist/daml-interface/emission/registry-emitter.d.ts +1 -0
- package/dist/daml-interface/emission/registry-emitter.js +15 -8
- package/dist/daml-interface/emission/support-file-emitter.d.ts +16 -1
- package/dist/daml-interface/emission/support-file-emitter.js +206 -6
- package/dist/daml-interface/emission/template-binding-emitter.d.ts +25 -1
- package/dist/daml-interface/emission/template-binding-emitter.js +373 -72
- package/dist/daml-interface/emission/type-script-name-resolver.d.ts +50 -3
- package/dist/daml-interface/emission/type-script-name-resolver.js +369 -11
- package/dist/daml-interface/emission-model/generated-choice-binding.d.ts +7 -0
- package/dist/daml-interface/emission-model/generated-choice-binding.js +6 -0
- package/dist/daml-interface/emission-model/generated-daml-interface-project.d.ts +3 -0
- package/dist/daml-interface/emission-model/generated-daml-interface-project.js +2 -0
- package/dist/daml-interface/emission-model/generated-named-type-file.d.ts +23 -0
- package/dist/daml-interface/emission-model/generated-named-type-file.js +23 -0
- package/dist/daml-interface/emission-model/generated-template-binding.d.ts +9 -0
- package/dist/daml-interface/emission-model/generated-template-binding.js +8 -0
- package/dist/daml-interface/index.d.ts +12 -0
- package/dist/daml-interface/index.js +9 -0
- package/dist/daml-interface/runtime/daml-event-source-normalizer.d.ts +52 -0
- package/dist/daml-interface/runtime/daml-event-source-normalizer.js +364 -0
- package/dist/daml-interface/runtime/daml-materialization-error.d.ts +5 -0
- package/dist/daml-interface/runtime/daml-materialization-error.js +9 -0
- package/dist/daml-interface/runtime/daml-template.d.ts +6 -0
- package/dist/daml-interface/runtime/daml-template.js +10 -0
- package/dist/daml-interface/runtime/daml-type-descriptor.d.ts +71 -0
- package/dist/daml-interface/runtime/daml-type-descriptor.js +1 -0
- package/dist/daml-interface/runtime/daml-value-converter.d.ts +7 -0
- package/dist/daml-interface/runtime/daml-value-converter.js +370 -0
- package/dist/daml-interface/runtime/daml-value-materializer.d.ts +3 -0
- package/dist/daml-interface/runtime/daml-value-materializer.js +23 -0
- package/dist/daml-interface/writing/daml-interface-writer.js +1 -0
- package/dist/daml-lf/daml-lf-compilation.d.ts +1 -0
- package/dist/daml-lf/daml-lf-compilation.js +24 -3
- package/dist/daml-lf/model/daml-lf-builtin-type.d.ts +9 -0
- package/dist/daml-lf/model/daml-lf-builtin-type.js +9 -0
- package/dist/daml-lf/model/daml-lf-data-type.d.ts +18 -1
- package/dist/daml-lf/model/daml-lf-data-type.js +8 -1
- package/dist/daml-lf/model/daml-lf-type.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-type.js +2 -0
- package/dist/daml-lf/model/lf-2-model-mapper.d.ts +1 -0
- package/dist/daml-lf/model/lf-2-model-mapper.js +81 -25
- package/dist/daml-lf/semantics/daml-lf-semantic-model.d.ts +3 -0
- package/dist/daml-lf/semantics/daml-lf-semantic-model.js +5 -1
- package/dist/query/pqs/pqs-query-client.js +15 -0
- package/dist/query/pqs/pqs-sql-compiler.js +35 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# Canton TypeScript SDK
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for Canton with
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
TypeScript SDK for Canton with:
|
|
4
|
+
|
|
5
|
+
- a shared `CantonClient`
|
|
6
|
+
- gRPC and JSON transports
|
|
7
|
+
- gRPC Ledger API-shaped service boundaries
|
|
8
|
+
- PQS-backed relational queries
|
|
9
|
+
- external-party lifecycle and signing
|
|
10
|
+
- authenticated and TLS-secured channels
|
|
11
|
+
- experimental tooling for invariant testing, DAML-LF inspection, interface
|
|
12
|
+
generation, and replay debugging
|
|
8
13
|
|
|
9
14
|
## Install
|
|
10
15
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnalyzedDamlType } from "./analyzed-daml-type.js";
|
|
2
2
|
export declare class AnalyzedChoice {
|
|
3
3
|
readonly name: string;
|
|
4
4
|
readonly methodName: string;
|
|
5
5
|
readonly parameterName: string;
|
|
6
|
-
readonly parameterType:
|
|
7
|
-
readonly returnType:
|
|
6
|
+
readonly parameterType: AnalyzedDamlType;
|
|
7
|
+
readonly returnType: AnalyzedDamlType;
|
|
8
8
|
constructor(init: {
|
|
9
9
|
name: string;
|
|
10
10
|
methodName: string;
|
|
11
11
|
parameterName: string;
|
|
12
|
-
parameterType:
|
|
13
|
-
returnType:
|
|
12
|
+
parameterType: AnalyzedDamlType;
|
|
13
|
+
returnType: AnalyzedDamlType;
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnalyzedDamlEnumType, AnalyzedDamlRecordType, AnalyzedDamlVariantType } from "./analyzed-daml-type.js";
|
|
2
|
+
import { TypeConReference } from "../../daml-lf/model/type-con-reference.js";
|
|
3
|
+
/** A reachable named DAML data type and its complete serializable shape. */
|
|
4
|
+
export type AnalyzedDamlTypeDefinition = {
|
|
5
|
+
readonly identity: TypeConReference;
|
|
6
|
+
} & (AnalyzedDamlRecordType | AnalyzedDamlVariantType | AnalyzedDamlEnumType);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DamlLfBuiltinType } from "../../daml-lf/model/daml-lf-builtin-type.js";
|
|
2
|
+
import { TypeConReference } from "../../daml-lf/model/type-con-reference.js";
|
|
3
|
+
export type AnalyzedDamlPrimitiveType = {
|
|
4
|
+
readonly kind: "primitive";
|
|
5
|
+
readonly builtinType: DamlLfBuiltinType.unit | DamlLfBuiltinType.bool | DamlLfBuiltinType.int64 | DamlLfBuiltinType.date | DamlLfBuiltinType.timestamp | DamlLfBuiltinType.numeric | DamlLfBuiltinType.party | DamlLfBuiltinType.text;
|
|
6
|
+
readonly numericScale?: number;
|
|
7
|
+
};
|
|
8
|
+
export type AnalyzedDamlContractIdType = {
|
|
9
|
+
readonly kind: "contractId";
|
|
10
|
+
};
|
|
11
|
+
export type AnalyzedDamlOptionalType = {
|
|
12
|
+
readonly kind: "optional";
|
|
13
|
+
readonly element: AnalyzedDamlType;
|
|
14
|
+
};
|
|
15
|
+
export type AnalyzedDamlListType = {
|
|
16
|
+
readonly kind: "list";
|
|
17
|
+
readonly element: AnalyzedDamlType;
|
|
18
|
+
};
|
|
19
|
+
export type AnalyzedDamlTextMapType = {
|
|
20
|
+
readonly kind: "textMap";
|
|
21
|
+
readonly value: AnalyzedDamlType;
|
|
22
|
+
};
|
|
23
|
+
export type AnalyzedDamlGenMapType = {
|
|
24
|
+
readonly kind: "genMap";
|
|
25
|
+
readonly key: AnalyzedDamlType;
|
|
26
|
+
readonly value: AnalyzedDamlType;
|
|
27
|
+
};
|
|
28
|
+
export type AnalyzedDamlRecordField = {
|
|
29
|
+
readonly damlLabel: string;
|
|
30
|
+
readonly propertyName: string;
|
|
31
|
+
readonly type: AnalyzedDamlType;
|
|
32
|
+
};
|
|
33
|
+
export type AnalyzedDamlRecordType = {
|
|
34
|
+
readonly kind: "record";
|
|
35
|
+
readonly fields: readonly AnalyzedDamlRecordField[];
|
|
36
|
+
};
|
|
37
|
+
export type AnalyzedDamlVariantConstructor = {
|
|
38
|
+
readonly constructor: string;
|
|
39
|
+
readonly payload: AnalyzedDamlType;
|
|
40
|
+
};
|
|
41
|
+
export type AnalyzedDamlVariantType = {
|
|
42
|
+
readonly kind: "variant";
|
|
43
|
+
readonly constructors: readonly AnalyzedDamlVariantConstructor[];
|
|
44
|
+
};
|
|
45
|
+
export type AnalyzedDamlEnumType = {
|
|
46
|
+
readonly kind: "enum";
|
|
47
|
+
readonly constructors: readonly string[];
|
|
48
|
+
};
|
|
49
|
+
export type AnalyzedDamlNamedReferenceType = {
|
|
50
|
+
readonly kind: "namedReference";
|
|
51
|
+
readonly identity: TypeConReference;
|
|
52
|
+
};
|
|
53
|
+
/** Closed, immutable description of a DAML value serializable by the generator. */
|
|
54
|
+
export type AnalyzedDamlType = AnalyzedDamlPrimitiveType | AnalyzedDamlContractIdType | AnalyzedDamlOptionalType | AnalyzedDamlListType | AnalyzedDamlTextMapType | AnalyzedDamlGenMapType | AnalyzedDamlRecordType | AnalyzedDamlVariantType | AnalyzedDamlEnumType | AnalyzedDamlNamedReferenceType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { DamlLfTemplateId } from "../../daml-lf/model/daml-lf-template-id.js";
|
|
2
|
-
import { DamlLfType } from "../../daml-lf/model/daml-lf-type.js";
|
|
3
2
|
import { AnalyzedChoice } from "./analyzed-choice.js";
|
|
3
|
+
import { AnalyzedDamlType } from "./analyzed-daml-type.js";
|
|
4
4
|
export declare class AnalyzedTemplateField {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
readonly propertyName: string;
|
|
7
|
-
readonly type:
|
|
7
|
+
readonly type: AnalyzedDamlType;
|
|
8
8
|
constructor(init: {
|
|
9
9
|
name: string;
|
|
10
10
|
propertyName: string;
|
|
11
|
-
type:
|
|
11
|
+
type: AnalyzedDamlType;
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
export declare class AnalyzedTemplate {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { DamlLfCompilation } from "../../daml-lf/daml-lf-compilation.js";
|
|
2
|
+
import { AnalyzedDamlTypeDefinition } from "./analyzed-daml-type-definition.js";
|
|
2
3
|
import { AnalyzedTemplate } from "./analyzed-template.js";
|
|
3
4
|
export declare class DamlInterfaceAnalysisResult {
|
|
4
5
|
readonly templates: readonly AnalyzedTemplate[];
|
|
6
|
+
readonly typeDefinitions: readonly AnalyzedDamlTypeDefinition[];
|
|
5
7
|
constructor(init: {
|
|
6
8
|
templates: readonly AnalyzedTemplate[];
|
|
9
|
+
typeDefinitions: readonly AnalyzedDamlTypeDefinition[];
|
|
7
10
|
});
|
|
8
11
|
}
|
|
9
12
|
export declare class DamlInterfaceAnalyzer {
|
|
@@ -12,7 +15,6 @@ export declare class DamlInterfaceAnalyzer {
|
|
|
12
15
|
private analyzeTemplateOrThrow;
|
|
13
16
|
private analyzeTemplateFieldOrThrow;
|
|
14
17
|
private analyzeChoiceOrThrow;
|
|
15
|
-
private assertSupportedTypeOrThrow;
|
|
16
18
|
private toCamelCase;
|
|
17
19
|
private toPascalCase;
|
|
18
20
|
private toKebabCase;
|
|
@@ -1,58 +1,57 @@
|
|
|
1
1
|
import { DamlLfBuiltinType } from "../../daml-lf/model/daml-lf-builtin-type.js";
|
|
2
|
+
import { TypeConReference } from "../../daml-lf/model/type-con-reference.js";
|
|
2
3
|
import { DamlInterfaceUnsupportedShapeException } from "../errors/daml-interface-unsupported-shape.exception.js";
|
|
3
4
|
import { AnalyzedChoice } from "./analyzed-choice.js";
|
|
4
5
|
import { AnalyzedTemplate, AnalyzedTemplateField } from "./analyzed-template.js";
|
|
5
6
|
export class DamlInterfaceAnalysisResult {
|
|
6
7
|
templates;
|
|
8
|
+
typeDefinitions;
|
|
7
9
|
constructor(init) {
|
|
8
|
-
this.templates = init.templates;
|
|
10
|
+
this.templates = Object.freeze([...init.templates]);
|
|
11
|
+
this.typeDefinitions = Object.freeze([...init.typeDefinitions]);
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
14
|
export class DamlInterfaceAnalyzer {
|
|
12
15
|
/** Analyzes compiled DAML-LF templates into generator-facing metadata. */
|
|
13
16
|
analyzeOrThrow(compilation) {
|
|
14
17
|
const semanticModel = compilation.createSemanticModel();
|
|
18
|
+
const typeBuilder = new AnalyzedDamlTypeBuilder(semanticModel, (value) => this.toCamelCase(value));
|
|
15
19
|
const templates = semanticModel
|
|
16
20
|
.getTemplates()
|
|
17
|
-
.map((item) => this.analyzeTemplateOrThrow(item));
|
|
21
|
+
.map((item) => this.analyzeTemplateOrThrow(item, typeBuilder));
|
|
18
22
|
return new DamlInterfaceAnalysisResult({
|
|
19
23
|
templates,
|
|
24
|
+
typeDefinitions: typeBuilder.getTypeDefinitions(),
|
|
20
25
|
});
|
|
21
26
|
}
|
|
22
|
-
analyzeTemplateOrThrow(template) {
|
|
27
|
+
analyzeTemplateOrThrow(template, typeBuilder) {
|
|
23
28
|
return new AnalyzedTemplate({
|
|
24
29
|
templateId: template.templateId,
|
|
25
30
|
className: this.toPascalCase(template.name),
|
|
26
31
|
fileName: `${this.toKebabCase(template.name)}.ts`,
|
|
27
|
-
createFields: template.fields.map((item) => this.analyzeTemplateFieldOrThrow(item)),
|
|
28
|
-
choices: template.choices.map((item) => this.analyzeChoiceOrThrow(item)),
|
|
32
|
+
createFields: template.fields.map((item) => this.analyzeTemplateFieldOrThrow(item, typeBuilder)),
|
|
33
|
+
choices: template.choices.map((item) => this.analyzeChoiceOrThrow(item, typeBuilder)),
|
|
29
34
|
});
|
|
30
35
|
}
|
|
31
|
-
analyzeTemplateFieldOrThrow(field) {
|
|
32
|
-
|
|
36
|
+
analyzeTemplateFieldOrThrow(field, typeBuilder) {
|
|
37
|
+
const type = typeBuilder.buildOrThrow(field.type, `template field '${field.name}'`);
|
|
33
38
|
return new AnalyzedTemplateField({
|
|
34
39
|
name: field.name,
|
|
35
40
|
propertyName: this.toCamelCase(field.name),
|
|
36
|
-
type
|
|
41
|
+
type,
|
|
37
42
|
});
|
|
38
43
|
}
|
|
39
|
-
analyzeChoiceOrThrow(choice) {
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
analyzeChoiceOrThrow(choice, typeBuilder) {
|
|
45
|
+
const parameterType = typeBuilder.buildOrThrow(choice.parameter.type, `choice parameter '${choice.parameter.name}'`);
|
|
46
|
+
const returnType = typeBuilder.buildOrThrow(choice.returnType, `choice return type '${choice.name}'`);
|
|
42
47
|
return new AnalyzedChoice({
|
|
43
48
|
name: choice.name,
|
|
44
49
|
methodName: `exercise${this.toPascalCase(choice.name)}`,
|
|
45
50
|
parameterName: this.toCamelCase(choice.parameter.name),
|
|
46
|
-
parameterType
|
|
47
|
-
returnType
|
|
51
|
+
parameterType,
|
|
52
|
+
returnType,
|
|
48
53
|
});
|
|
49
54
|
}
|
|
50
|
-
assertSupportedTypeOrThrow(type, context) {
|
|
51
|
-
if (type.typeConReference !== undefined ||
|
|
52
|
-
type.builtinType !== DamlLfBuiltinType.text) {
|
|
53
|
-
throw new DamlInterfaceUnsupportedShapeException(`${context} is not supported yet by the DAML interface generator`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
55
|
toCamelCase(value) {
|
|
57
56
|
const pascalCase = this.toPascalCase(value);
|
|
58
57
|
if (pascalCase.length === 0) {
|
|
@@ -79,3 +78,168 @@ export class DamlInterfaceAnalyzer {
|
|
|
79
78
|
.toLowerCase();
|
|
80
79
|
}
|
|
81
80
|
}
|
|
81
|
+
class AnalyzedDamlTypeBuilder {
|
|
82
|
+
semanticModel;
|
|
83
|
+
toCamelCase;
|
|
84
|
+
definitionKeys = [];
|
|
85
|
+
canonicalIdentities = new Map();
|
|
86
|
+
definitions = new Map();
|
|
87
|
+
constructor(semanticModel, toCamelCase) {
|
|
88
|
+
this.semanticModel = semanticModel;
|
|
89
|
+
this.toCamelCase = toCamelCase;
|
|
90
|
+
}
|
|
91
|
+
buildOrThrow(type, context) {
|
|
92
|
+
if (type.typeConReference !== undefined) {
|
|
93
|
+
if (type.builtinType !== DamlLfBuiltinType.unknown) {
|
|
94
|
+
throw this.unsupported(context, "a type constructor cannot also be a builtin type");
|
|
95
|
+
}
|
|
96
|
+
else if (type.typeArguments.length !== 0) {
|
|
97
|
+
throw this.unsupported(context, "generic named type applications are not supported");
|
|
98
|
+
}
|
|
99
|
+
return this.buildNamedReferenceOrThrow(type.typeConReference, context);
|
|
100
|
+
}
|
|
101
|
+
switch (type.builtinType) {
|
|
102
|
+
case DamlLfBuiltinType.unit:
|
|
103
|
+
case DamlLfBuiltinType.bool:
|
|
104
|
+
case DamlLfBuiltinType.int64:
|
|
105
|
+
case DamlLfBuiltinType.date:
|
|
106
|
+
case DamlLfBuiltinType.timestamp:
|
|
107
|
+
case DamlLfBuiltinType.party:
|
|
108
|
+
case DamlLfBuiltinType.text:
|
|
109
|
+
this.assertArgumentCountOrThrow(type, 0, context);
|
|
110
|
+
return Object.freeze({
|
|
111
|
+
kind: "primitive",
|
|
112
|
+
builtinType: type.builtinType,
|
|
113
|
+
...(type.numericScale === undefined
|
|
114
|
+
? {}
|
|
115
|
+
: { numericScale: type.numericScale }),
|
|
116
|
+
});
|
|
117
|
+
case DamlLfBuiltinType.numeric:
|
|
118
|
+
this.assertArgumentCountOrThrow(type, 0, context);
|
|
119
|
+
if (type.numericScale === undefined ||
|
|
120
|
+
!Number.isInteger(type.numericScale) ||
|
|
121
|
+
type.numericScale < 0 ||
|
|
122
|
+
type.numericScale > 37) {
|
|
123
|
+
throw this.unsupported(context, "numeric values require an integer scale from 0 through 37");
|
|
124
|
+
}
|
|
125
|
+
return Object.freeze({
|
|
126
|
+
kind: "primitive",
|
|
127
|
+
builtinType: type.builtinType,
|
|
128
|
+
numericScale: type.numericScale,
|
|
129
|
+
});
|
|
130
|
+
case DamlLfBuiltinType.contractId:
|
|
131
|
+
this.assertArgumentCountOrThrow(type, 1, context);
|
|
132
|
+
return Object.freeze({
|
|
133
|
+
kind: "contractId",
|
|
134
|
+
});
|
|
135
|
+
case DamlLfBuiltinType.optional:
|
|
136
|
+
return Object.freeze({
|
|
137
|
+
kind: "optional",
|
|
138
|
+
element: this.buildUnaryArgumentOrThrow(type, context),
|
|
139
|
+
});
|
|
140
|
+
case DamlLfBuiltinType.list:
|
|
141
|
+
return Object.freeze({
|
|
142
|
+
kind: "list",
|
|
143
|
+
element: this.buildUnaryArgumentOrThrow(type, context),
|
|
144
|
+
});
|
|
145
|
+
case DamlLfBuiltinType.textMap:
|
|
146
|
+
return Object.freeze({
|
|
147
|
+
kind: "textMap",
|
|
148
|
+
value: this.buildUnaryArgumentOrThrow(type, context),
|
|
149
|
+
});
|
|
150
|
+
case DamlLfBuiltinType.genMap:
|
|
151
|
+
this.assertArgumentCountOrThrow(type, 2, context);
|
|
152
|
+
return Object.freeze({
|
|
153
|
+
kind: "genMap",
|
|
154
|
+
key: this.buildOrThrow(type.typeArguments[0], context),
|
|
155
|
+
value: this.buildOrThrow(type.typeArguments[1], context),
|
|
156
|
+
});
|
|
157
|
+
case DamlLfBuiltinType.unknown:
|
|
158
|
+
throw this.unsupported(context, "the type is not serializable");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
getTypeDefinitions() {
|
|
162
|
+
return Object.freeze(this.definitionKeys.map((key) => {
|
|
163
|
+
const definition = this.definitions.get(key);
|
|
164
|
+
if (definition === undefined) {
|
|
165
|
+
throw new DamlInterfaceUnsupportedShapeException(`could not finish resolving named DAML type '${key}'`);
|
|
166
|
+
}
|
|
167
|
+
return definition;
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
buildUnaryArgumentOrThrow(type, context) {
|
|
171
|
+
this.assertArgumentCountOrThrow(type, 1, context);
|
|
172
|
+
return this.buildOrThrow(type.typeArguments[0], context);
|
|
173
|
+
}
|
|
174
|
+
buildNamedReferenceOrThrow(reference, context) {
|
|
175
|
+
const key = this.getDefinitionKey(reference);
|
|
176
|
+
const identity = this.getCanonicalIdentity(reference, key);
|
|
177
|
+
if (!this.definitions.has(key)) {
|
|
178
|
+
this.definitionKeys.push(key);
|
|
179
|
+
this.definitions.set(key, undefined);
|
|
180
|
+
this.definitions.set(key, this.buildNamedDefinitionOrThrow(reference, identity, context));
|
|
181
|
+
}
|
|
182
|
+
return Object.freeze({
|
|
183
|
+
kind: "namedReference",
|
|
184
|
+
identity,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
buildNamedDefinitionOrThrow(reference, identity, context) {
|
|
188
|
+
let dataType;
|
|
189
|
+
try {
|
|
190
|
+
dataType = this.semanticModel.getDataTypeOrThrow(reference);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw this.unsupported(context, `could not resolve named type '${reference.name}'`);
|
|
194
|
+
}
|
|
195
|
+
if (dataType.definition.kind === "record") {
|
|
196
|
+
return Object.freeze({
|
|
197
|
+
identity,
|
|
198
|
+
kind: "record",
|
|
199
|
+
fields: Object.freeze(dataType.definition.fields.map((field) => Object.freeze({
|
|
200
|
+
damlLabel: field.name,
|
|
201
|
+
propertyName: this.toCamelCase(field.name),
|
|
202
|
+
type: this.buildOrThrow(field.type, `field '${field.name}' of record '${reference.name}'`),
|
|
203
|
+
}))),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else if (dataType.definition.kind === "variant") {
|
|
207
|
+
return Object.freeze({
|
|
208
|
+
identity,
|
|
209
|
+
kind: "variant",
|
|
210
|
+
constructors: Object.freeze(dataType.definition.constructors.map((constructor) => Object.freeze({
|
|
211
|
+
constructor: constructor.name,
|
|
212
|
+
payload: this.buildOrThrow(constructor.type, `constructor '${constructor.name}' of variant '${reference.name}'`),
|
|
213
|
+
}))),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return Object.freeze({
|
|
217
|
+
identity,
|
|
218
|
+
kind: "enum",
|
|
219
|
+
constructors: Object.freeze([...dataType.definition.constructors]),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
assertArgumentCountOrThrow(type, expectedCount, context) {
|
|
223
|
+
if (type.typeArguments.length !== expectedCount) {
|
|
224
|
+
throw this.unsupported(context, `builtin '${type.builtinType}' requires ${expectedCount} type argument${expectedCount === 1 ? "" : "s"}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
getDefinitionKey(reference) {
|
|
228
|
+
return `${reference.packageId}::${reference.moduleName}::${reference.name}`;
|
|
229
|
+
}
|
|
230
|
+
getCanonicalIdentity(reference, key) {
|
|
231
|
+
let identity = this.canonicalIdentities.get(key);
|
|
232
|
+
if (identity === undefined) {
|
|
233
|
+
identity = Object.freeze(new TypeConReference({
|
|
234
|
+
packageId: reference.packageId,
|
|
235
|
+
moduleName: reference.moduleName,
|
|
236
|
+
name: reference.name,
|
|
237
|
+
}));
|
|
238
|
+
this.canonicalIdentities.set(key, identity);
|
|
239
|
+
}
|
|
240
|
+
return identity;
|
|
241
|
+
}
|
|
242
|
+
unsupported(context, reason) {
|
|
243
|
+
return new DamlInterfaceUnsupportedShapeException(`${context} is not supported by the DAML interface generator: ${reason}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AnalyzedDamlTypeDefinition } from "../analysis/analyzed-daml-type-definition.js";
|
|
2
|
+
import { GeneratedNamedTypeFile } from "../emission-model/generated-named-type-file.js";
|
|
3
|
+
import { GeneratedTemplateBindingFile } from "../emission-model/generated-template-binding-file.js";
|
|
4
|
+
import { TypeScriptNameResolver } from "./type-script-name-resolver.js";
|
|
5
|
+
/** Emits TypeScript declarations for reachable named DAML records, variants, and enums. */
|
|
6
|
+
export declare class NamedTypeEmitter {
|
|
7
|
+
private readonly nameResolver;
|
|
8
|
+
constructor(nameResolver?: TypeScriptNameResolver);
|
|
9
|
+
/** Prepares shared package/module output mappings with template emission. */
|
|
10
|
+
prepareProjectOrThrow(templates: readonly import("../analysis/analyzed-template.js").AnalyzedTemplate[], definitions: readonly AnalyzedDamlTypeDefinition[]): void;
|
|
11
|
+
/** Emits one `types.ts` module for every reachable DAML package/module identity. */
|
|
12
|
+
emitNamedTypeFiles(definitions: readonly AnalyzedDamlTypeDefinition[]): readonly GeneratedNamedTypeFile[];
|
|
13
|
+
/** Emits named type files from an already prepared shared name resolver. */
|
|
14
|
+
emitPreparedNamedTypeFiles(definitions: readonly AnalyzedDamlTypeDefinition[], templateFiles?: readonly GeneratedTemplateBindingFile[]): readonly GeneratedNamedTypeFile[];
|
|
15
|
+
private emitDefinition;
|
|
16
|
+
private emitImports;
|
|
17
|
+
private resolveExternalTypeAliases;
|
|
18
|
+
private getExternalTypeAlias;
|
|
19
|
+
private getNamedReferences;
|
|
20
|
+
private getTypeName;
|
|
21
|
+
private getPrimitiveTypeName;
|
|
22
|
+
private resolveModulesOrThrow;
|
|
23
|
+
private resolveDefinitionNamesOrThrow;
|
|
24
|
+
private resolveCollisionSafeNames;
|
|
25
|
+
private getReservedModuleExports;
|
|
26
|
+
private getReservedRuntimeBindings;
|
|
27
|
+
private mergeReservedNames;
|
|
28
|
+
private resolveFieldPropertyNames;
|
|
29
|
+
private getFieldPropertyName;
|
|
30
|
+
private getFieldKey;
|
|
31
|
+
private safePropertyName;
|
|
32
|
+
private getModuleKeyFromTemplateIdentity;
|
|
33
|
+
private relativeFilePath;
|
|
34
|
+
private getDefinitionName;
|
|
35
|
+
private getNamedReferenceTypeName;
|
|
36
|
+
private getModuleKey;
|
|
37
|
+
private getDefinitionKey;
|
|
38
|
+
private safeTypeName;
|
|
39
|
+
private getRuntimePrimitiveTypes;
|
|
40
|
+
private shortHash;
|
|
41
|
+
}
|