@distrohelena/canton-typescript-sdk 0.1.22 → 0.1.25

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.
Files changed (65) hide show
  1. package/README.md +7 -3
  2. package/dist/daml-interface/analysis/analyzed-choice.d.ts +5 -5
  3. package/dist/daml-interface/analysis/analyzed-daml-type-definition.d.ts +6 -0
  4. package/dist/daml-interface/analysis/analyzed-daml-type-definition.js +1 -0
  5. package/dist/daml-interface/analysis/analyzed-daml-type.d.ts +55 -0
  6. package/dist/daml-interface/analysis/analyzed-daml-type.js +1 -0
  7. package/dist/daml-interface/analysis/analyzed-template.d.ts +3 -3
  8. package/dist/daml-interface/analysis/daml-interface-analyzer.d.ts +3 -1
  9. package/dist/daml-interface/analysis/daml-interface-analyzer.js +183 -19
  10. package/dist/daml-interface/emission/named-type-emitter.d.ts +41 -0
  11. package/dist/daml-interface/emission/named-type-emitter.js +445 -0
  12. package/dist/daml-interface/emission/project-emitter.d.ts +5 -1
  13. package/dist/daml-interface/emission/project-emitter.js +20 -3
  14. package/dist/daml-interface/emission/registry-emitter.d.ts +1 -0
  15. package/dist/daml-interface/emission/registry-emitter.js +15 -8
  16. package/dist/daml-interface/emission/support-file-emitter.d.ts +16 -1
  17. package/dist/daml-interface/emission/support-file-emitter.js +206 -6
  18. package/dist/daml-interface/emission/template-binding-emitter.d.ts +25 -1
  19. package/dist/daml-interface/emission/template-binding-emitter.js +371 -72
  20. package/dist/daml-interface/emission/type-script-name-resolver.d.ts +50 -3
  21. package/dist/daml-interface/emission/type-script-name-resolver.js +369 -11
  22. package/dist/daml-interface/emission-model/generated-choice-binding.d.ts +7 -0
  23. package/dist/daml-interface/emission-model/generated-choice-binding.js +6 -0
  24. package/dist/daml-interface/emission-model/generated-daml-interface-project.d.ts +3 -0
  25. package/dist/daml-interface/emission-model/generated-daml-interface-project.js +2 -0
  26. package/dist/daml-interface/emission-model/generated-named-type-file.d.ts +23 -0
  27. package/dist/daml-interface/emission-model/generated-named-type-file.js +23 -0
  28. package/dist/daml-interface/emission-model/generated-template-binding.d.ts +9 -0
  29. package/dist/daml-interface/emission-model/generated-template-binding.js +8 -0
  30. package/dist/daml-interface/index.d.ts +12 -0
  31. package/dist/daml-interface/index.js +9 -0
  32. package/dist/daml-interface/runtime/daml-event-source-normalizer.d.ts +52 -0
  33. package/dist/daml-interface/runtime/daml-event-source-normalizer.js +364 -0
  34. package/dist/daml-interface/runtime/daml-materialization-error.d.ts +5 -0
  35. package/dist/daml-interface/runtime/daml-materialization-error.js +9 -0
  36. package/dist/daml-interface/runtime/daml-template.d.ts +6 -0
  37. package/dist/daml-interface/runtime/daml-template.js +10 -0
  38. package/dist/daml-interface/runtime/daml-type-descriptor.d.ts +71 -0
  39. package/dist/daml-interface/runtime/daml-type-descriptor.js +1 -0
  40. package/dist/daml-interface/runtime/daml-value-converter.d.ts +7 -0
  41. package/dist/daml-interface/runtime/daml-value-converter.js +370 -0
  42. package/dist/daml-interface/runtime/daml-value-materializer.d.ts +3 -0
  43. package/dist/daml-interface/runtime/daml-value-materializer.js +23 -0
  44. package/dist/daml-interface/writing/daml-interface-writer.js +1 -0
  45. package/dist/daml-lf/daml-lf-compilation.d.ts +1 -0
  46. package/dist/daml-lf/daml-lf-compilation.js +17 -3
  47. package/dist/daml-lf/model/daml-lf-builtin-type.d.ts +9 -0
  48. package/dist/daml-lf/model/daml-lf-builtin-type.js +9 -0
  49. package/dist/daml-lf/model/daml-lf-data-type.d.ts +18 -1
  50. package/dist/daml-lf/model/daml-lf-data-type.js +8 -1
  51. package/dist/daml-lf/model/daml-lf-type.d.ts +2 -0
  52. package/dist/daml-lf/model/daml-lf-type.js +2 -0
  53. package/dist/daml-lf/model/lf-2-model-mapper.d.ts +1 -0
  54. package/dist/daml-lf/model/lf-2-model-mapper.js +81 -25
  55. package/dist/daml-lf/semantics/daml-lf-semantic-model.d.ts +3 -0
  56. package/dist/daml-lf/semantics/daml-lf-semantic-model.js +5 -1
  57. package/dist/query/pqs/pqs-query-client.js +15 -0
  58. package/dist/query/pqs/pqs-sql-compiler.js +35 -7
  59. package/node/.generated/start-local/additional-config.extra-participants.conf +107 -0
  60. package/node/.generated/start-local/additional-config.extra-validators.conf +85 -0
  61. package/node/.generated/start-local/compose-extra-participants.yaml +312 -0
  62. package/node/.generated/start-local/extra-participants.env +58 -0
  63. package/node/start-local.sh +69 -29
  64. package/node/test-start-local.sh +49 -8
  65. package/package.json +1 -1
@@ -1,43 +1,401 @@
1
1
  import { DamlLfBuiltinType } from "../../daml-lf/model/daml-lf-builtin-type.js";
2
+ const typeScriptKeywords = new Set([
3
+ "as", "async", "await", "break", "case", "catch", "class", "const", "continue",
4
+ "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false",
5
+ "finally", "for", "from", "function", "get", "if", "implements", "import", "in",
6
+ "instanceof", "interface", "let", "new", "null", "of", "package", "private", "protected",
7
+ "public", "return", "set", "static", "super", "switch", "this", "throw", "true", "try",
8
+ "type", "typeof", "undefined", "var", "void", "while", "with", "yield",
9
+ ]);
10
+ const damlTemplateMemberNames = new Set([
11
+ "constructor", "get", "contractId", "templateId", "create", "decodeCreatedEvent",
12
+ "decodeExercisedEvent",
13
+ ]);
14
+ const reservedTypeNames = new Set(["DamlTemplate"]);
15
+ const reservedNamespaceAliases = new Set(["GeneratedRegistry"]);
2
16
  export class TypeScriptNameResolver {
17
+ templatesByIdentity = new Map();
18
+ resolvedTemplates = new Map();
19
+ resolvedModules = new Map();
20
+ constructor(templates = []) {
21
+ this.prepareTemplatesOrThrow(templates);
22
+ }
23
+ /** Prepares a project-wide name table and rejects irreconcilable output collisions. */
24
+ prepareTemplatesOrThrow(templates) {
25
+ this.prepareProjectOrThrow(templates, []);
26
+ }
27
+ /** Prepares shared package/module paths for template and named DAML type output. */
28
+ prepareProjectOrThrow(templates, typeDefinitions) {
29
+ this.templatesByIdentity.clear();
30
+ this.resolvedTemplates.clear();
31
+ this.resolvedModules.clear();
32
+ for (const template of templates) {
33
+ const identityKey = this.getTemplateIdentityKey(template);
34
+ const existing = this.templatesByIdentity.get(identityKey);
35
+ if (existing !== undefined) {
36
+ throw new Error(`Cannot generate duplicate DAML template identity '${this.describeTemplate(template)}' `
37
+ + `and '${this.describeTemplate(existing)}'`);
38
+ }
39
+ this.templatesByIdentity.set(identityKey, template);
40
+ }
41
+ const allTemplates = [...this.templatesByIdentity.values()];
42
+ const modulesByIdentity = new Map();
43
+ for (const template of allTemplates) {
44
+ modulesByIdentity.set(this.getPackageModuleIdentityKey(template), {
45
+ packageId: template.templateId.packageId,
46
+ moduleName: template.templateId.moduleName,
47
+ });
48
+ }
49
+ for (const definition of typeDefinitions) {
50
+ modulesByIdentity.set(this.getPackageModuleIdentityKeyFromParts(definition.identity.packageId, definition.identity.moduleName), {
51
+ packageId: definition.identity.packageId,
52
+ moduleName: definition.identity.moduleName,
53
+ });
54
+ }
55
+ const packageIds = [...new Set([...modulesByIdentity.values()].map((module) => module.packageId))];
56
+ const packageDirectories = this.resolveNames(packageIds.map((packageId) => ({
57
+ value: packageId,
58
+ key: `package\u0000${packageId}`,
59
+ baseName: this.toKebabCase(packageId),
60
+ scope: "packages",
61
+ })));
62
+ const moduleDirectories = this.resolveNames([...modulesByIdentity.entries()].map(([identityKey, module]) => ({
63
+ value: identityKey,
64
+ key: `module\u0000${identityKey}`,
65
+ baseName: this.getModuleDirectory(module.moduleName),
66
+ scope: module.packageId,
67
+ })));
68
+ const fileNames = this.resolveNames(allTemplates.map((template) => ({
69
+ value: template,
70
+ key: this.getTemplateIdentityKey(template),
71
+ baseName: this.getTemplateFileBaseName(template),
72
+ scope: `${template.templateId.packageId}\u0000${template.templateId.moduleName}`,
73
+ })));
74
+ const namespaceAliases = this.resolveNames([...modulesByIdentity.entries()].map(([identityKey, module]) => ({
75
+ value: identityKey,
76
+ key: `namespace\u0000${identityKey}`,
77
+ baseName: this.safeNamespaceAlias(`${module.packageId} ${module.moduleName}`),
78
+ collisionSeparator: "_",
79
+ })));
80
+ const classNames = this.resolveNames(allTemplates.map((template) => ({
81
+ value: template,
82
+ key: this.getTemplateIdentityKey(template),
83
+ baseName: this.safeTypeName(template.templateId.templateName),
84
+ collisionSeparator: "_",
85
+ })));
86
+ this.resolvedModules = new Map([...modulesByIdentity.entries()].map(([identityKey, module]) => {
87
+ const packageDirectory = packageDirectories.get(module.packageId);
88
+ const moduleDirectory = moduleDirectories.get(identityKey);
89
+ const namespaceAlias = namespaceAliases.get(identityKey);
90
+ if (packageDirectory === undefined || moduleDirectory === undefined || namespaceAlias === undefined) {
91
+ throw new Error(`Could not resolve generated path for '${module.packageId}:${module.moduleName}'`);
92
+ }
93
+ return [
94
+ identityKey,
95
+ {
96
+ ...module,
97
+ directoryPath: `generated/packages/${packageDirectory}/${moduleDirectory}`,
98
+ namespaceAlias,
99
+ },
100
+ ];
101
+ }));
102
+ this.resolvedTemplates = new Map(allTemplates.map((template) => {
103
+ const identityKey = this.getTemplateIdentityKey(template);
104
+ const className = classNames.get(template);
105
+ if (className === undefined) {
106
+ throw new Error(`Could not resolve generated class name for '${this.describeTemplate(template)}'`);
107
+ }
108
+ const fileName = fileNames.get(template);
109
+ const module = this.resolvedModules.get(this.getPackageModuleIdentityKey(template));
110
+ if (fileName === undefined ||
111
+ module === undefined) {
112
+ throw new Error(`Could not resolve generated path for '${this.describeTemplate(template)}'`);
113
+ }
114
+ return [
115
+ identityKey,
116
+ {
117
+ template,
118
+ identityKey,
119
+ namespaceAlias: module.namespaceAlias,
120
+ filePath: `${module.directoryPath}/${fileName}.ts`,
121
+ className,
122
+ fieldNames: this.resolveFieldNames(template),
123
+ choiceNames: this.resolveChoiceNames(template, className, identityKey),
124
+ },
125
+ ];
126
+ }));
127
+ this.assertDistinctTemplateOutput("file path", (resolved) => resolved.filePath);
128
+ this.assertDistinctNamespaceAliases(namespaceAliases);
129
+ this.assertDistinctTemplateOutput("class name", (resolved) => resolved.className);
130
+ }
131
+ /** Resolves the full package/module/entity identity key for a template. */
132
+ getTemplateIdentityKey(template) {
133
+ return [
134
+ template.templateId.packageId,
135
+ template.templateId.moduleName,
136
+ template.templateId.templateName,
137
+ ].join("\u0000");
138
+ }
139
+ /** Resolves the generated namespace alias for a template package/module. */
140
+ getNamespaceAlias(template) {
141
+ return this.getResolvedTemplate(template).namespaceAlias;
142
+ }
3
143
  /** Resolves the generated file path for a template binding. */
4
144
  getTemplateFilePath(template) {
5
- return `generated/${this.getModuleDirectory(template)}/${template.fileName}`;
145
+ return this.getResolvedTemplate(template).filePath;
146
+ }
147
+ /** Resolves the generated class name for a template binding. */
148
+ getTemplateClassName(template) {
149
+ return this.getResolvedTemplate(template).className;
150
+ }
151
+ /** Resolves the output directory shared by a named DAML type package/module. */
152
+ getNamedTypeModuleDirectoryPath(packageId, moduleName) {
153
+ return this.getResolvedModule(packageId, moduleName).directoryPath;
154
+ }
155
+ /** Resolves the generated namespace alias shared by templates and named DAML types. */
156
+ getNamedTypeModuleNamespaceAlias(packageId, moduleName) {
157
+ return this.getResolvedModule(packageId, moduleName).namespaceAlias;
6
158
  }
7
159
  /** Resolves the generated create-fields type name for a template. */
8
160
  getCreateFieldsTypeName(template) {
9
- return `${template.className}CreateFields`;
161
+ return `${this.getTemplateClassName(template)}Fields`;
10
162
  }
11
163
  /** Resolves the generated created-event type name for a template. */
12
164
  getCreatedEventTypeName(template) {
13
- return `${template.className}CreatedEvent`;
165
+ return `${this.getTemplateClassName(template)}CreatedEvent`;
166
+ }
167
+ /** Resolves the generated property name for an original DAML template field. */
168
+ getFieldPropertyName(template, field) {
169
+ return this.getResolvedField(template, field).propertyName;
170
+ }
171
+ /** Resolves the generated constructor parameter for an original DAML template field. */
172
+ getFieldConstructorParameterName(template, field) {
173
+ return this.getResolvedField(template, field).constructorParameterName;
174
+ }
175
+ /** Resolves the generated exercise method name for a DAML choice. */
176
+ getChoiceMethodName(template, choice) {
177
+ return this.getResolvedChoice(template, choice).methodName;
14
178
  }
15
179
  /** Resolves the generated choice payload type name for a template choice. */
16
180
  getChoiceTypeName(template, choice) {
17
- return `${template.className}${choice.name}Choice`;
181
+ return this.getResolvedChoice(template, choice).choiceTypeName;
18
182
  }
19
183
  /** Resolves the generated exercised-event type name for a template choice. */
20
184
  getExercisedEventTypeName(template, choice) {
21
- return `${template.className}${choice.name}ExercisedEvent`;
185
+ return this.getResolvedChoice(template, choice).exercisedEventTypeName;
186
+ }
187
+ /** Resolves the generated parameter property name for a DAML choice. */
188
+ getChoiceParameterName(template, choice) {
189
+ return this.getResolvedChoice(template, choice).parameterName;
190
+ }
191
+ /** Resolves the full identity key for a DAML choice. */
192
+ getChoiceIdentityKey(template, choice) {
193
+ return this.getResolvedChoice(template, choice).identityKey;
22
194
  }
23
195
  /** Resolves the TypeScript type name for a supported DAML-LF type. */
24
196
  getTypeName(type) {
25
- return type.builtinType === DamlLfBuiltinType.text ? "string" : "unknown";
197
+ return type.kind === "primitive" && type.builtinType === DamlLfBuiltinType.text
198
+ ? "string"
199
+ : "unknown";
26
200
  }
27
201
  /** Resolves the literal template identifier used by generated helpers. */
28
202
  getTemplateIdLiteral(template) {
29
- return `${template.templateId.moduleName}:${template.templateId.templateName}`;
203
+ return `${template.templateId.packageId}:${template.templateId.moduleName}:${template.templateId.templateName}`;
204
+ }
205
+ getResolvedTemplate(template) {
206
+ const identityKey = this.getTemplateIdentityKey(template);
207
+ if (!this.resolvedTemplates.has(identityKey)) {
208
+ this.prepareTemplatesOrThrow([template]);
209
+ }
210
+ const resolved = this.resolvedTemplates.get(identityKey);
211
+ if (resolved === undefined) {
212
+ throw new Error(`Could not resolve DAML template '${this.describeTemplate(template)}'`);
213
+ }
214
+ return resolved;
215
+ }
216
+ getResolvedModule(packageId, moduleName) {
217
+ const module = this.resolvedModules.get(this.getPackageModuleIdentityKeyFromParts(packageId, moduleName));
218
+ if (module === undefined) {
219
+ throw new Error(`Could not resolve DAML module '${packageId}:${moduleName}'`);
220
+ }
221
+ return module;
222
+ }
223
+ getResolvedField(template, field) {
224
+ const resolved = this.getResolvedTemplate(template).fieldNames.get(field);
225
+ if (resolved === undefined) {
226
+ throw new Error(`Could not resolve field '${field.name}' for '${this.describeTemplate(template)}'`);
227
+ }
228
+ return resolved;
30
229
  }
31
- getModuleDirectory(template) {
32
- return template.templateId.moduleName
230
+ getResolvedChoice(template, choice) {
231
+ const resolved = this.getResolvedTemplate(template).choiceNames.get(choice);
232
+ if (resolved === undefined) {
233
+ throw new Error(`Could not resolve choice '${choice.name}' for '${this.describeTemplate(template)}'`);
234
+ }
235
+ return resolved;
236
+ }
237
+ resolveFieldNames(template) {
238
+ const propertyNames = this.resolveNames(template.createFields.map((field, index) => ({
239
+ value: field,
240
+ key: `${this.getTemplateIdentityKey(template)}\u0000field\u0000${field.name}\u0000${index}`,
241
+ baseName: this.safeMemberName(field.name),
242
+ collisionSeparator: "_",
243
+ })));
244
+ return new Map(template.createFields.map((field) => {
245
+ const propertyName = propertyNames.get(field);
246
+ if (propertyName === undefined) {
247
+ throw new Error(`Could not resolve field '${field.name}' for '${this.describeTemplate(template)}'`);
248
+ }
249
+ return [field, { propertyName, constructorParameterName: propertyName }];
250
+ }));
251
+ }
252
+ resolveChoiceNames(template, className, templateIdentityKey) {
253
+ const stems = this.resolveNames(template.choices.map((choice, index) => ({
254
+ value: choice,
255
+ key: `${templateIdentityKey}\u0000choice\u0000${choice.name}\u0000${index}`,
256
+ baseName: this.safeTypeName(choice.name),
257
+ collisionSeparator: "_",
258
+ })));
259
+ return new Map(template.choices.map((choice) => {
260
+ const stem = stems.get(choice);
261
+ if (stem === undefined) {
262
+ throw new Error(`Could not resolve choice '${choice.name}' for '${this.describeTemplate(template)}'`);
263
+ }
264
+ const choiceIdentityKey = `${templateIdentityKey}\u0000${choice.name}`;
265
+ return [
266
+ choice,
267
+ {
268
+ methodName: this.safeMemberName(`exercise${stem}`),
269
+ choiceTypeName: `${className}${stem}Choice`,
270
+ exercisedEventTypeName: `${className}${stem}ExercisedEvent`,
271
+ parameterName: this.safeMemberName(choice.parameterName),
272
+ identityKey: choiceIdentityKey,
273
+ },
274
+ ];
275
+ }));
276
+ }
277
+ resolveNames(values) {
278
+ const groups = new Map();
279
+ for (const value of values) {
280
+ const groupKey = `${value.scope ?? ""}\u0000${value.baseName}`;
281
+ groups.set(groupKey, (groups.get(groupKey) ?? 0) + 1);
282
+ }
283
+ const names = new Map();
284
+ const allocatedNamesByScope = new Map();
285
+ for (const value of [...values].sort((left, right) => left.key.localeCompare(right.key))) {
286
+ const scope = value.scope ?? "";
287
+ const groupKey = `${scope}\u0000${value.baseName}`;
288
+ const groupSize = groups.get(groupKey);
289
+ if (groupSize === undefined) {
290
+ throw new Error(`Could not resolve generated name '${value.baseName}'`);
291
+ }
292
+ const collisionSuffix = `${value.collisionSeparator ?? "-"}${this.shortHash(value.key)}`;
293
+ const baseCandidate = groupSize === 1
294
+ ? value.baseName
295
+ : `${value.baseName}${collisionSuffix}`;
296
+ const allocatedNames = allocatedNamesByScope.get(scope) ?? new Set();
297
+ let candidate = baseCandidate;
298
+ let escalation = 2;
299
+ while (allocatedNames.has(candidate)) {
300
+ candidate = `${baseCandidate}_${escalation}`;
301
+ escalation += 1;
302
+ }
303
+ allocatedNames.add(candidate);
304
+ allocatedNamesByScope.set(scope, allocatedNames);
305
+ names.set(value.value, candidate);
306
+ }
307
+ return names;
308
+ }
309
+ assertDistinctTemplateOutput(outputName, getOutput) {
310
+ const outputs = new Map();
311
+ for (const resolved of this.resolvedTemplates.values()) {
312
+ const output = getOutput(resolved);
313
+ const existing = outputs.get(output);
314
+ if (existing !== undefined && existing.identityKey !== resolved.identityKey) {
315
+ throw new Error(`Cannot resolve generated ${outputName} '${output}' for `
316
+ + `'${this.describeTemplate(existing.template)}' and '${this.describeTemplate(resolved.template)}'`);
317
+ }
318
+ outputs.set(output, resolved);
319
+ }
320
+ }
321
+ assertDistinctNamespaceAliases(namespaceAliases) {
322
+ const identitiesByAlias = new Map();
323
+ for (const [identityKey, alias] of namespaceAliases) {
324
+ const existingIdentityKey = identitiesByAlias.get(alias);
325
+ if (existingIdentityKey !== undefined && existingIdentityKey !== identityKey) {
326
+ throw new Error(`Cannot resolve generated namespace alias '${alias}' for `
327
+ + `'${existingIdentityKey.replaceAll("\u0000", ":")}' and `
328
+ + `'${identityKey.replaceAll("\u0000", ":")}'`);
329
+ }
330
+ identitiesByAlias.set(alias, identityKey);
331
+ }
332
+ }
333
+ getModuleDirectory(moduleName) {
334
+ return moduleName
33
335
  .split(".")
34
336
  .map((segment) => this.toKebabCase(segment))
35
337
  .join("/");
36
338
  }
339
+ getTemplateFileBaseName(template) {
340
+ const fileName = this.toKebabCase(template.templateId.templateName);
341
+ return fileName === "index" || fileName === "types"
342
+ ? `${fileName}-template`
343
+ : fileName;
344
+ }
345
+ getPackageModuleIdentityKey(template) {
346
+ return this.getPackageModuleIdentityKeyFromParts(template.templateId.packageId, template.templateId.moduleName);
347
+ }
348
+ getPackageModuleIdentityKeyFromParts(packageId, moduleName) {
349
+ return [packageId, moduleName].join("\u0000");
350
+ }
351
+ safeTypeName(value) {
352
+ const identifier = this.toPascalCase(value);
353
+ const safeIdentifier = /^[0-9]/.test(identifier) ? `_${identifier}` : identifier;
354
+ return reservedTypeNames.has(safeIdentifier)
355
+ ? `${safeIdentifier}Binding`
356
+ : safeIdentifier;
357
+ }
358
+ safeNamespaceAlias(value) {
359
+ const alias = this.safeTypeName(value);
360
+ return reservedNamespaceAliases.has(alias)
361
+ ? `${alias}Namespace`
362
+ : alias;
363
+ }
364
+ safeMemberName(value) {
365
+ const pascalCase = this.toPascalCase(value);
366
+ const identifier = `${pascalCase[0].toLowerCase()}${pascalCase.slice(1)}`;
367
+ const safeIdentifier = /^[0-9]/.test(identifier) ? `_${identifier}` : identifier;
368
+ return typeScriptKeywords.has(safeIdentifier) || damlTemplateMemberNames.has(safeIdentifier)
369
+ ? `${safeIdentifier}Value`
370
+ : safeIdentifier;
371
+ }
372
+ toPascalCase(value) {
373
+ const normalizedValue = value
374
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
375
+ .replace(/[^A-Za-z0-9]+/g, " ")
376
+ .trim();
377
+ if (normalizedValue.length === 0) {
378
+ throw new Error("Cannot normalize an empty DAML identifier");
379
+ }
380
+ return normalizedValue
381
+ .split(/\s+/)
382
+ .map((segment) => segment[0].toUpperCase() + segment.slice(1))
383
+ .join("");
384
+ }
37
385
  toKebabCase(value) {
38
- return value
386
+ return this.toPascalCase(value)
39
387
  .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
40
- .replace(/[^A-Za-z0-9]+/g, "-")
41
388
  .toLowerCase();
42
389
  }
390
+ shortHash(value) {
391
+ let hash = 0x811c9dc5;
392
+ for (const character of value) {
393
+ hash ^= character.charCodeAt(0);
394
+ hash = Math.imul(hash, 0x01000193);
395
+ }
396
+ return (hash >>> 0).toString(36).padStart(6, "0").slice(-6);
397
+ }
398
+ describeTemplate(template) {
399
+ return `${template.templateId.packageId}:${template.templateId.moduleName}:${template.templateId.templateName}`;
400
+ }
43
401
  }
@@ -1,18 +1,25 @@
1
+ import { AnalyzedDamlType } from "../analysis/analyzed-daml-type.js";
1
2
  export declare class GeneratedChoiceBinding {
3
+ readonly choiceIdentityKey: string;
2
4
  readonly name: string;
3
5
  readonly methodName: string;
4
6
  readonly choiceTypeName: string;
5
7
  readonly exercisedEventTypeName: string;
6
8
  readonly parameterName: string;
7
9
  readonly parameterTypeName: string;
10
+ readonly parameterType: AnalyzedDamlType;
8
11
  readonly returnTypeName: string;
12
+ readonly returnType: AnalyzedDamlType;
9
13
  constructor(init: {
14
+ choiceIdentityKey?: string;
10
15
  name: string;
11
16
  methodName: string;
12
17
  choiceTypeName: string;
13
18
  exercisedEventTypeName: string;
14
19
  parameterName: string;
15
20
  parameterTypeName: string;
21
+ parameterType: AnalyzedDamlType;
16
22
  returnTypeName: string;
23
+ returnType: AnalyzedDamlType;
17
24
  });
18
25
  }
@@ -1,18 +1,24 @@
1
1
  export class GeneratedChoiceBinding {
2
+ choiceIdentityKey;
2
3
  name;
3
4
  methodName;
4
5
  choiceTypeName;
5
6
  exercisedEventTypeName;
6
7
  parameterName;
7
8
  parameterTypeName;
9
+ parameterType;
8
10
  returnTypeName;
11
+ returnType;
9
12
  constructor(init) {
13
+ this.choiceIdentityKey = init.choiceIdentityKey ?? init.name;
10
14
  this.name = init.name;
11
15
  this.methodName = init.methodName;
12
16
  this.choiceTypeName = init.choiceTypeName;
13
17
  this.exercisedEventTypeName = init.exercisedEventTypeName;
14
18
  this.parameterName = init.parameterName;
15
19
  this.parameterTypeName = init.parameterTypeName;
20
+ this.parameterType = init.parameterType;
16
21
  this.returnTypeName = init.returnTypeName;
22
+ this.returnType = init.returnType;
17
23
  }
18
24
  }
@@ -1,13 +1,16 @@
1
+ import { GeneratedNamedTypeFile } from "./generated-named-type-file.js";
1
2
  import { GeneratedRegistryFile } from "./generated-registry-file.js";
2
3
  import { GeneratedSupportFile } from "./generated-support-file.js";
3
4
  import { GeneratedTemplateBindingFile } from "./generated-template-binding-file.js";
4
5
  export declare class GeneratedDamlInterfaceProject {
5
6
  readonly templateFiles: readonly GeneratedTemplateBindingFile[];
7
+ readonly namedTypeFiles: readonly GeneratedNamedTypeFile[];
6
8
  readonly supportFiles: readonly GeneratedSupportFile[];
7
9
  readonly registryFile?: GeneratedRegistryFile;
8
10
  readonly indexFile?: GeneratedSupportFile;
9
11
  constructor(init: {
10
12
  templateFiles: readonly GeneratedTemplateBindingFile[];
13
+ namedTypeFiles?: readonly GeneratedNamedTypeFile[];
11
14
  supportFiles?: readonly GeneratedSupportFile[];
12
15
  registryFile?: GeneratedRegistryFile;
13
16
  indexFile?: GeneratedSupportFile;
@@ -1,10 +1,12 @@
1
1
  export class GeneratedDamlInterfaceProject {
2
2
  templateFiles;
3
+ namedTypeFiles;
3
4
  supportFiles;
4
5
  registryFile;
5
6
  indexFile;
6
7
  constructor(init) {
7
8
  this.templateFiles = init.templateFiles;
9
+ this.namedTypeFiles = init.namedTypeFiles ?? [];
8
10
  this.supportFiles = init.supportFiles ?? [];
9
11
  this.registryFile = init.registryFile;
10
12
  this.indexFile = init.indexFile;
@@ -0,0 +1,23 @@
1
+ /** A generated module containing declarations for one DAML package/module identity. */
2
+ export declare class GeneratedNamedTypeFile {
3
+ readonly path: string;
4
+ readonly contents: string;
5
+ readonly packageId: string;
6
+ readonly moduleName: string;
7
+ readonly namespaceAlias: string;
8
+ readonly exportedTypeNames: readonly string[];
9
+ /** Resolved exported type names keyed by package, module, and DAML entity name. */
10
+ readonly exportedTypeNamesByIdentity: ReadonlyMap<string, string>;
11
+ /** Resolved record property names keyed by named type identity, field label, and position. */
12
+ readonly fieldPropertyNames: ReadonlyMap<string, string>;
13
+ constructor(init: {
14
+ path: string;
15
+ contents: string;
16
+ packageId: string;
17
+ moduleName: string;
18
+ namespaceAlias: string;
19
+ exportedTypeNames: readonly string[];
20
+ exportedTypeNamesByIdentity?: ReadonlyMap<string, string>;
21
+ fieldPropertyNames?: ReadonlyMap<string, string>;
22
+ });
23
+ }
@@ -0,0 +1,23 @@
1
+ /** A generated module containing declarations for one DAML package/module identity. */
2
+ export class GeneratedNamedTypeFile {
3
+ path;
4
+ contents;
5
+ packageId;
6
+ moduleName;
7
+ namespaceAlias;
8
+ exportedTypeNames;
9
+ /** Resolved exported type names keyed by package, module, and DAML entity name. */
10
+ exportedTypeNamesByIdentity;
11
+ /** Resolved record property names keyed by named type identity, field label, and position. */
12
+ fieldPropertyNames;
13
+ constructor(init) {
14
+ this.path = init.path;
15
+ this.contents = init.contents;
16
+ this.packageId = init.packageId;
17
+ this.moduleName = init.moduleName;
18
+ this.namespaceAlias = init.namespaceAlias;
19
+ this.exportedTypeNames = init.exportedTypeNames;
20
+ this.exportedTypeNamesByIdentity = init.exportedTypeNamesByIdentity ?? new Map();
21
+ this.fieldPropertyNames = init.fieldPropertyNames ?? new Map();
22
+ }
23
+ }
@@ -1,15 +1,22 @@
1
1
  import { GeneratedChoiceBinding } from "./generated-choice-binding.js";
2
+ import { AnalyzedDamlType } from "../analysis/analyzed-daml-type.js";
2
3
  export declare class GeneratedTemplateBindingField {
3
4
  readonly name: string;
4
5
  readonly propertyName: string;
6
+ readonly constructorParameterName: string;
7
+ readonly type: AnalyzedDamlType;
5
8
  readonly typeName: string;
6
9
  constructor(init: {
7
10
  name: string;
8
11
  propertyName: string;
12
+ constructorParameterName?: string;
13
+ type: AnalyzedDamlType;
9
14
  typeName: string;
10
15
  });
11
16
  }
12
17
  export declare class GeneratedTemplateBinding {
18
+ readonly templateIdentityKey: string;
19
+ readonly namespaceAlias: string;
13
20
  readonly className: string;
14
21
  readonly templateIdLiteral: string;
15
22
  readonly path: string;
@@ -18,6 +25,8 @@ export declare class GeneratedTemplateBinding {
18
25
  readonly createFields: readonly GeneratedTemplateBindingField[];
19
26
  readonly choices: readonly GeneratedChoiceBinding[];
20
27
  constructor(init: {
28
+ templateIdentityKey?: string;
29
+ namespaceAlias?: string;
21
30
  className: string;
22
31
  templateIdLiteral: string;
23
32
  path: string;
@@ -1,14 +1,20 @@
1
1
  export class GeneratedTemplateBindingField {
2
2
  name;
3
3
  propertyName;
4
+ constructorParameterName;
5
+ type;
4
6
  typeName;
5
7
  constructor(init) {
6
8
  this.name = init.name;
7
9
  this.propertyName = init.propertyName;
10
+ this.constructorParameterName = init.constructorParameterName ?? init.propertyName;
11
+ this.type = init.type;
8
12
  this.typeName = init.typeName;
9
13
  }
10
14
  }
11
15
  export class GeneratedTemplateBinding {
16
+ templateIdentityKey;
17
+ namespaceAlias;
12
18
  className;
13
19
  templateIdLiteral;
14
20
  path;
@@ -17,6 +23,8 @@ export class GeneratedTemplateBinding {
17
23
  createFields;
18
24
  choices;
19
25
  constructor(init) {
26
+ this.templateIdentityKey = init.templateIdentityKey ?? init.templateIdLiteral;
27
+ this.namespaceAlias = init.namespaceAlias ?? init.className;
20
28
  this.className = init.className;
21
29
  this.templateIdLiteral = init.templateIdLiteral;
22
30
  this.path = init.path;
@@ -7,7 +7,19 @@ export { DamlInterfaceGenerator } from "./daml-interface-generator.js";
7
7
  export { DamlInterfaceGeneratorOptions } from "./daml-interface-generator-options.js";
8
8
  export { GeneratedDamlInterfaceProject } from "./emission-model/generated-daml-interface-project.js";
9
9
  export { GeneratedTemplateBindingFile } from "./emission-model/generated-template-binding-file.js";
10
+ export { GeneratedNamedTypeFile } from "./emission-model/generated-named-type-file.js";
10
11
  export { DamlInterfaceGenerationException } from "./errors/daml-interface-generation.exception.js";
11
12
  export { DamlInterfaceUnsupportedShapeException } from "./errors/daml-interface-unsupported-shape.exception.js";
12
13
  export { DamlInterfaceWriteException } from "./errors/daml-interface-write.exception.js";
13
14
  export { DamlInterfaceWriter } from "./writing/daml-interface-writer.js";
15
+ export { DamlTemplate } from "./runtime/daml-template.js";
16
+ export { DamlMaterializationError } from "./runtime/daml-materialization-error.js";
17
+ export { decodeDamlValue } from "./runtime/daml-value-converter.js";
18
+ export { materializeDamlValue } from "./runtime/daml-value-materializer.js";
19
+ export { normalizeDamlCreatedEventSource, normalizeDamlExercisedEventSource, } from "./runtime/daml-event-source-normalizer.js";
20
+ export { DamlNumeric } from "../core/types/daml-numeric.js";
21
+ export { DamlParty } from "../core/types/daml-party.js";
22
+ export { DamlDate, DamlEnum, DamlGenMap, DamlRecord, DamlTextMap, DamlTimestamp, DamlUnit, DamlVariant, } from "../core/types/daml-values.js";
23
+ export type { DamlDecodedValue, } from "./runtime/daml-value-converter.js";
24
+ export type { DamlCreatedEventMetadata, DamlCreatedEventSource, DamlExercisedEventMetadata, DamlExercisedEventSource, DamlJsonEventRecord, DamlNormalizedCreatedEvent, DamlNormalizedExercisedEvent, } from "./runtime/daml-event-source-normalizer.js";
25
+ export type { DamlContractIdDescriptor, DamlEnumDescriptor, DamlGenMapDescriptor, DamlListDescriptor, DamlNamedReferenceDescriptor, DamlOptionalDescriptor, DamlPrimitiveDescriptor, DamlPrimitiveType, DamlRecordDescriptor, DamlRecordFieldDescriptor, DamlTextMapDescriptor, DamlTypeDescriptor, DamlTypeDescriptorRegistry, DamlTypeIdentity, DamlValueSource, DamlVariantConstructorDescriptor, DamlVariantDescriptor, } from "./runtime/daml-type-descriptor.js";
@@ -7,7 +7,16 @@ export { DamlInterfaceGenerator } from "./daml-interface-generator.js";
7
7
  export { DamlInterfaceGeneratorOptions } from "./daml-interface-generator-options.js";
8
8
  export { GeneratedDamlInterfaceProject } from "./emission-model/generated-daml-interface-project.js";
9
9
  export { GeneratedTemplateBindingFile } from "./emission-model/generated-template-binding-file.js";
10
+ export { GeneratedNamedTypeFile } from "./emission-model/generated-named-type-file.js";
10
11
  export { DamlInterfaceGenerationException } from "./errors/daml-interface-generation.exception.js";
11
12
  export { DamlInterfaceUnsupportedShapeException } from "./errors/daml-interface-unsupported-shape.exception.js";
12
13
  export { DamlInterfaceWriteException } from "./errors/daml-interface-write.exception.js";
13
14
  export { DamlInterfaceWriter } from "./writing/daml-interface-writer.js";
15
+ export { DamlTemplate } from "./runtime/daml-template.js";
16
+ export { DamlMaterializationError } from "./runtime/daml-materialization-error.js";
17
+ export { decodeDamlValue } from "./runtime/daml-value-converter.js";
18
+ export { materializeDamlValue } from "./runtime/daml-value-materializer.js";
19
+ export { normalizeDamlCreatedEventSource, normalizeDamlExercisedEventSource, } from "./runtime/daml-event-source-normalizer.js";
20
+ export { DamlNumeric } from "../core/types/daml-numeric.js";
21
+ export { DamlParty } from "../core/types/daml-party.js";
22
+ export { DamlDate, DamlEnum, DamlGenMap, DamlRecord, DamlTextMap, DamlTimestamp, DamlUnit, DamlVariant, } from "../core/types/daml-values.js";