@distrohelena/canton-typescript-sdk 0.1.25 → 0.1.27
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/daml-interface/analysis/analyzed-daml-type.d.ts +0 -1
- package/dist/daml-interface/analysis/daml-interface-analyzer.js +3 -3
- package/dist/daml-interface/daml-interface-generator.js +2 -2
- package/dist/daml-interface/emission/named-type-emitter.js +2 -6
- package/dist/daml-interface/emission/support-file-emitter.js +1 -1
- package/dist/daml-interface/emission/template-binding-emitter.js +10 -8
- package/dist/daml-interface/emission/type-script-name-resolver.js +2 -2
- package/dist/daml-interface/runtime/daml-template.d.ts +1 -1
- package/dist/daml-interface/runtime/daml-template.js +1 -1
- package/dist/daml-interface/runtime/daml-type-descriptor.d.ts +1 -1
- package/dist/daml-lf/daml-lf-compilation.d.ts +1 -0
- package/dist/daml-lf/daml-lf-compilation.js +12 -0
- package/package.json +1 -1
|
@@ -128,9 +128,9 @@ class AnalyzedDamlTypeBuilder {
|
|
|
128
128
|
numericScale: type.numericScale,
|
|
129
129
|
});
|
|
130
130
|
case DamlLfBuiltinType.contractId:
|
|
131
|
+
this.assertArgumentCountOrThrow(type, 1, context);
|
|
131
132
|
return Object.freeze({
|
|
132
133
|
kind: "contractId",
|
|
133
|
-
contract: this.buildUnaryArgumentOrThrow(type, context),
|
|
134
134
|
});
|
|
135
135
|
case DamlLfBuiltinType.optional:
|
|
136
136
|
return Object.freeze({
|
|
@@ -189,8 +189,8 @@ class AnalyzedDamlTypeBuilder {
|
|
|
189
189
|
try {
|
|
190
190
|
dataType = this.semanticModel.getDataTypeOrThrow(reference);
|
|
191
191
|
}
|
|
192
|
-
catch
|
|
193
|
-
throw this.unsupported(context, `could not resolve named type '${reference.name}'`);
|
|
192
|
+
catch {
|
|
193
|
+
throw this.unsupported(context, `could not resolve named type '${reference.packageId}:${reference.moduleName}:${reference.name}'`);
|
|
194
194
|
}
|
|
195
195
|
if (dataType.definition.kind === "record") {
|
|
196
196
|
return Object.freeze({
|
|
@@ -29,14 +29,14 @@ export class DamlInterfaceGenerator {
|
|
|
29
29
|
/** Generates an in-memory project from compiled DAML-LF archive bytes. */
|
|
30
30
|
async generateFromDalfOrThrowAsync(archiveBytes) {
|
|
31
31
|
const pkg = this.packageLoader.loadPackageOrThrow(archiveBytes);
|
|
32
|
-
const compilation = DamlLfCompilation.
|
|
32
|
+
const compilation = DamlLfCompilation.createForTemplateGeneration(new DamlLfWorkspace([pkg]));
|
|
33
33
|
return this.projectEmitter.emitProject(this.analyzeOrThrow(compilation));
|
|
34
34
|
}
|
|
35
35
|
/** Generates an in-memory project from DAR bytes. */
|
|
36
36
|
async generateFromDarOrThrowAsync(archiveBytes) {
|
|
37
37
|
const archive = await this.darArchiveLoader.loadDarOrThrowAsync(archiveBytes);
|
|
38
38
|
const packages = archive.packageEntries.map((entry) => this.packageLoader.loadPackageOrThrow(entry.bytes));
|
|
39
|
-
const compilation = DamlLfCompilation.
|
|
39
|
+
const compilation = DamlLfCompilation.createForTemplateGeneration(new DamlLfWorkspace(packages));
|
|
40
40
|
return this.projectEmitter.emitProject(this.analyzeOrThrow(compilation));
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -139,9 +139,7 @@ export class NamedTypeEmitter {
|
|
|
139
139
|
case "namedReference":
|
|
140
140
|
yield type;
|
|
141
141
|
return;
|
|
142
|
-
case "contractId":
|
|
143
|
-
yield* this.getNamedReferences(type.contract);
|
|
144
|
-
return;
|
|
142
|
+
case "contractId": return;
|
|
145
143
|
case "optional":
|
|
146
144
|
case "list":
|
|
147
145
|
yield* this.getNamedReferences(type.element);
|
|
@@ -405,9 +403,7 @@ export class NamedTypeEmitter {
|
|
|
405
403
|
}
|
|
406
404
|
return;
|
|
407
405
|
}
|
|
408
|
-
case "contractId":
|
|
409
|
-
yield* this.getRuntimePrimitiveTypes(type.contract);
|
|
410
|
-
return;
|
|
406
|
+
case "contractId": return;
|
|
411
407
|
case "optional":
|
|
412
408
|
case "list":
|
|
413
409
|
yield* this.getRuntimePrimitiveTypes(type.element);
|
|
@@ -186,7 +186,7 @@ export class SupportFileEmitter {
|
|
|
186
186
|
case "primitive":
|
|
187
187
|
return `{ kind: "primitive", primitive: ${JSON.stringify(type.builtinType)}${type.numericScale === undefined ? "" : `, numericScale: ${type.numericScale}`} }`;
|
|
188
188
|
case "contractId":
|
|
189
|
-
return
|
|
189
|
+
return '{ kind: "contractId" }';
|
|
190
190
|
case "optional":
|
|
191
191
|
return `{ kind: "optional", element: ${this.emitDescriptor(type.element)} }`;
|
|
192
192
|
case "list":
|
|
@@ -195,7 +195,7 @@ export class TemplateBindingEmitter {
|
|
|
195
195
|
case "primitive":
|
|
196
196
|
return `{ kind: "primitive", primitive: ${JSON.stringify(type.builtinType)}${type.numericScale === undefined ? "" : `, numericScale: ${type.numericScale}`} }`;
|
|
197
197
|
case "contractId":
|
|
198
|
-
return
|
|
198
|
+
return '{ kind: "contractId" }';
|
|
199
199
|
case "optional":
|
|
200
200
|
return `{ kind: "optional", element: ${this.emitDescriptor(type.element)} }`;
|
|
201
201
|
case "list":
|
|
@@ -255,13 +255,17 @@ export class TemplateBindingEmitter {
|
|
|
255
255
|
if ("kind" in type) {
|
|
256
256
|
return type;
|
|
257
257
|
}
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
else if (type.builtinType === DamlLfBuiltinType.contractId) {
|
|
259
|
+
if (type.typeArguments.length !== 1) {
|
|
260
|
+
throw new Error("DAML ContractId requires exactly one type argument");
|
|
261
|
+
}
|
|
262
|
+
return { kind: "contractId" };
|
|
263
|
+
}
|
|
264
|
+
else if (type.typeConReference !== undefined) {
|
|
260
265
|
return { kind: "namedReference", identity: type.typeConReference };
|
|
261
266
|
}
|
|
267
|
+
const arguments_ = type.typeArguments.map((argument) => this.normalizeType(argument));
|
|
262
268
|
switch (type.builtinType) {
|
|
263
|
-
case DamlLfBuiltinType.contractId:
|
|
264
|
-
return { kind: "contractId", contract: arguments_[0] ?? { kind: "primitive", builtinType: DamlLfBuiltinType.text } };
|
|
265
269
|
case DamlLfBuiltinType.optional:
|
|
266
270
|
return { kind: "optional", element: arguments_[0] ?? { kind: "primitive", builtinType: DamlLfBuiltinType.text } };
|
|
267
271
|
case DamlLfBuiltinType.list:
|
|
@@ -345,9 +349,7 @@ export class TemplateBindingEmitter {
|
|
|
345
349
|
case "namedReference":
|
|
346
350
|
yield type;
|
|
347
351
|
return;
|
|
348
|
-
case "contractId":
|
|
349
|
-
yield* this.walkNamedReferences(type.contract);
|
|
350
|
-
return;
|
|
352
|
+
case "contractId": return;
|
|
351
353
|
case "optional":
|
|
352
354
|
case "list":
|
|
353
355
|
yield* this.walkNamedReferences(type.element);
|
|
@@ -2,13 +2,13 @@ import { DamlLfBuiltinType } from "../../daml-lf/model/daml-lf-builtin-type.js";
|
|
|
2
2
|
const typeScriptKeywords = new Set([
|
|
3
3
|
"as", "async", "await", "break", "case", "catch", "class", "const", "continue",
|
|
4
4
|
"debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false",
|
|
5
|
-
"finally", "for", "from", "function", "
|
|
5
|
+
"finally", "for", "from", "function", "if", "implements", "import", "in",
|
|
6
6
|
"instanceof", "interface", "let", "new", "null", "of", "package", "private", "protected",
|
|
7
7
|
"public", "return", "set", "static", "super", "switch", "this", "throw", "true", "try",
|
|
8
8
|
"type", "typeof", "undefined", "var", "void", "while", "with", "yield",
|
|
9
9
|
]);
|
|
10
10
|
const damlTemplateMemberNames = new Set([
|
|
11
|
-
"constructor", "
|
|
11
|
+
"constructor", "contractId", "templateId", "create", "decodeCreatedEvent",
|
|
12
12
|
"decodeExercisedEvent",
|
|
13
13
|
]);
|
|
14
14
|
const reservedTypeNames = new Set(["DamlTemplate"]);
|
|
@@ -12,7 +12,7 @@ export type DamlPrimitiveDescriptor = {
|
|
|
12
12
|
};
|
|
13
13
|
export type DamlContractIdDescriptor = {
|
|
14
14
|
readonly kind: "contractId";
|
|
15
|
-
readonly contract
|
|
15
|
+
readonly contract?: DamlTypeDescriptor;
|
|
16
16
|
};
|
|
17
17
|
export type DamlOptionalDescriptor = {
|
|
18
18
|
readonly kind: "optional";
|
|
@@ -18,6 +18,7 @@ export declare class DamlLfCompilation {
|
|
|
18
18
|
private readonly valueDefinitionIdentities;
|
|
19
19
|
private constructor();
|
|
20
20
|
static createOrThrow(workspace: DamlLfWorkspace): DamlLfCompilation;
|
|
21
|
+
static createForTemplateGeneration(workspace: DamlLfWorkspace): DamlLfCompilation;
|
|
21
22
|
getModuleSymbolOrThrow(reference: ModuleReference): ModuleSymbol;
|
|
22
23
|
getTypeSymbolOrThrow(reference: TypeConReference): TypeSymbol;
|
|
23
24
|
createSemanticModel(): DamlLfSemanticModel;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DamlLfResolutionException } from "./errors/daml-lf-resolution.exception.js";
|
|
2
2
|
import { DamlLfSemanticException } from "./errors/daml-lf-semantic.exception.js";
|
|
3
|
+
import { DamlLfBuiltinType } from "./model/daml-lf-builtin-type.js";
|
|
3
4
|
import { DamlLfDataType } from "./model/daml-lf-data-type.js";
|
|
4
5
|
import { DamlLfTemplate } from "./model/daml-lf-template.js";
|
|
5
6
|
import { DamlLfValueDefinition } from "./model/daml-lf-value-definition.js";
|
|
@@ -24,6 +25,11 @@ export class DamlLfCompilation {
|
|
|
24
25
|
compilation.validateReferencesOrThrow();
|
|
25
26
|
return compilation;
|
|
26
27
|
}
|
|
28
|
+
static createForTemplateGeneration(workspace) {
|
|
29
|
+
const compilation = new DamlLfCompilation(workspace);
|
|
30
|
+
compilation.buildIndexes();
|
|
31
|
+
return compilation;
|
|
32
|
+
}
|
|
27
33
|
getModuleSymbolOrThrow(reference) {
|
|
28
34
|
const symbol = this.moduleSymbols.get(DamlLfCompilation.createModuleKey(reference.packageId, reference.moduleName));
|
|
29
35
|
if (symbol === undefined) {
|
|
@@ -122,6 +128,12 @@ export class DamlLfCompilation {
|
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
130
|
validateTypeOrThrow(type) {
|
|
131
|
+
if (type.builtinType === DamlLfBuiltinType.contractId) {
|
|
132
|
+
if (type.typeArguments.length !== 1) {
|
|
133
|
+
throw new DamlLfSemanticException("builtin 'contractId' requires 1 type argument");
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
125
137
|
for (const typeArgument of type.typeArguments) {
|
|
126
138
|
this.validateTypeOrThrow(typeArgument);
|
|
127
139
|
}
|