@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.
Files changed (59) hide show
  1. package/README.md +10 -5
  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 +54 -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 +441 -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 +373 -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 +24 -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/package.json +1 -1
@@ -33,15 +33,23 @@ export class Lf2ModelMapper {
33
33
  const numericScale = lhs.builtinType === DamlLfBuiltinType.numeric
34
34
  ? Lf2ModelMapper.readNumericScale(rawType.sum.tapp.rhs)
35
35
  : undefined;
36
- return numericScale === undefined
37
- ? lhs
38
- : new DamlLfType({
39
- builtinType: lhs.builtinType,
40
- numericScale,
41
- ...(lhs.typeConReference === undefined
36
+ return new DamlLfType({
37
+ builtinType: lhs.builtinType,
38
+ ...(numericScale === undefined
39
+ ? lhs.numericScale === undefined
42
40
  ? {}
43
- : { typeConReference: lhs.typeConReference }),
44
- });
41
+ : { numericScale: lhs.numericScale }
42
+ : { numericScale }),
43
+ ...(lhs.typeConReference === undefined
44
+ ? {}
45
+ : { typeConReference: lhs.typeConReference }),
46
+ typeArguments: numericScale === undefined
47
+ ? [
48
+ ...lhs.typeArguments,
49
+ Lf2ModelMapper.mapType(currentPackageId, rawPackage, rawType.sum.tapp.rhs),
50
+ ]
51
+ : lhs.typeArguments,
52
+ });
45
53
  }
46
54
  if (rawType?.sum.oneofKind === "forall") {
47
55
  return Lf2ModelMapper.mapType(currentPackageId, rawPackage, rawType.sum.forall.body);
@@ -49,31 +57,60 @@ export class Lf2ModelMapper {
49
57
  if (rawType?.sum.oneofKind === "con") {
50
58
  return new DamlLfType({
51
59
  typeConReference: Lf2ModelMapper.mapTypeConReferenceOrThrow(currentPackageId, rawPackage, rawType.sum.con.tycon, rawType),
60
+ typeArguments: rawType.sum.con.args.map((item) => Lf2ModelMapper.mapType(currentPackageId, rawPackage, item)),
52
61
  });
53
62
  }
54
63
  else if (rawType?.sum.oneofKind === "builtin") {
55
- const builtinType = rawType.sum.builtin.builtin === BuiltinType.INT64
56
- ? DamlLfBuiltinType.int64
57
- : rawType.sum.builtin.builtin === BuiltinType.NUMERIC
58
- ? DamlLfBuiltinType.numeric
59
- : rawType.sum.builtin.builtin === BuiltinType.PARTY
60
- ? DamlLfBuiltinType.party
61
- : rawType.sum.builtin.builtin === BuiltinType.TEXT
62
- ? DamlLfBuiltinType.text
63
- : DamlLfBuiltinType.unknown;
64
+ const builtinType = Lf2ModelMapper.mapBuiltinType(rawType.sum.builtin.builtin);
65
+ const numericScale = builtinType === DamlLfBuiltinType.numeric
66
+ ? Lf2ModelMapper.readNumericScale(rawType.sum.builtin.args[0])
67
+ : undefined;
64
68
  return new DamlLfType({
65
69
  builtinType,
66
- ...(builtinType !== DamlLfBuiltinType.numeric
70
+ ...(numericScale === undefined
67
71
  ? {}
68
- : {
69
- numericScale: Lf2ModelMapper.readNumericScale(rawType.sum.builtin.args[0]),
70
- }),
72
+ : { numericScale }),
73
+ typeArguments: rawType.sum.builtin.args
74
+ .slice(numericScale === undefined ? 0 : 1)
75
+ .map((item) => Lf2ModelMapper.mapType(currentPackageId, rawPackage, item)),
71
76
  });
72
77
  }
73
78
  return new DamlLfType({
74
79
  builtinType: DamlLfBuiltinType.unknown,
75
80
  });
76
81
  }
82
+ static mapBuiltinType(builtinType) {
83
+ switch (builtinType) {
84
+ case BuiltinType.UNIT:
85
+ return DamlLfBuiltinType.unit;
86
+ case BuiltinType.BOOL:
87
+ return DamlLfBuiltinType.bool;
88
+ case BuiltinType.INT64:
89
+ return DamlLfBuiltinType.int64;
90
+ case BuiltinType.DATE:
91
+ return DamlLfBuiltinType.date;
92
+ case BuiltinType.TIMESTAMP:
93
+ return DamlLfBuiltinType.timestamp;
94
+ case BuiltinType.NUMERIC:
95
+ return DamlLfBuiltinType.numeric;
96
+ case BuiltinType.PARTY:
97
+ return DamlLfBuiltinType.party;
98
+ case BuiltinType.TEXT:
99
+ return DamlLfBuiltinType.text;
100
+ case BuiltinType.CONTRACT_ID:
101
+ return DamlLfBuiltinType.contractId;
102
+ case BuiltinType.OPTIONAL:
103
+ return DamlLfBuiltinType.optional;
104
+ case BuiltinType.LIST:
105
+ return DamlLfBuiltinType.list;
106
+ case BuiltinType.TEXTMAP:
107
+ return DamlLfBuiltinType.textMap;
108
+ case BuiltinType.GENMAP:
109
+ return DamlLfBuiltinType.genMap;
110
+ default:
111
+ return DamlLfBuiltinType.unknown;
112
+ }
113
+ }
77
114
  static readNumericScale(rawType) {
78
115
  if (rawType?.sum.oneofKind !== "nat") {
79
116
  return undefined;
@@ -103,12 +140,31 @@ export class Lf2ModelMapper {
103
140
  });
104
141
  }
105
142
  static mapDataType(packageId, rawDataType, rawPackage) {
106
- const fields = rawDataType.dataCons.oneofKind === "record"
107
- ? rawDataType.dataCons.record.fields.map((item) => Lf2ModelMapper.mapField(packageId, item.fieldInternedStr, item.type, rawPackage))
108
- : [];
143
+ const definition = rawDataType.dataCons.oneofKind === "record"
144
+ ? {
145
+ kind: "record",
146
+ fields: rawDataType.dataCons.record.fields.map((item) => Lf2ModelMapper.mapField(packageId, item.fieldInternedStr, item.type, rawPackage)),
147
+ }
148
+ : rawDataType.dataCons.oneofKind === "variant"
149
+ ? {
150
+ kind: "variant",
151
+ constructors: rawDataType.dataCons.variant.fields.map((item) => ({
152
+ name: Lf2ModelMapper.resolveInternedString(rawPackage.internedStrings, item.fieldInternedStr),
153
+ type: Lf2ModelMapper.mapType(packageId, rawPackage, item.type),
154
+ })),
155
+ }
156
+ : rawDataType.dataCons.oneofKind === "enum"
157
+ ? {
158
+ kind: "enum",
159
+ constructors: rawDataType.dataCons.enum.constructorsInternedStr.map((item) => Lf2ModelMapper.resolveInternedString(rawPackage.internedStrings, item)),
160
+ }
161
+ : undefined;
162
+ if (definition === undefined) {
163
+ return undefined;
164
+ }
109
165
  return new DamlLfDataType({
110
166
  name: Lf2ModelMapper.resolveInternedDottedName(rawPackage.internedStrings, rawPackage.internedDottedNames, rawDataType.nameInternedDname),
111
- fields,
167
+ definition,
112
168
  });
113
169
  }
114
170
  static mapTemplateOrThrow(packageId, moduleName, rawTemplate, rawPackage, dataTypes) {
@@ -1,5 +1,6 @@
1
1
  import { DamlLfChoice } from "../model/daml-lf-choice.js";
2
2
  import { DamlLfCompilation } from "../daml-lf-compilation.js";
3
+ import { DamlLfDataType } from "../model/daml-lf-data-type.js";
3
4
  import { DamlLfField } from "../model/daml-lf-field.js";
4
5
  import { DamlLfTemplate } from "../model/daml-lf-template.js";
5
6
  import { DamlLfTemplateId } from "../model/daml-lf-template-id.js";
@@ -13,4 +14,6 @@ export declare class DamlLfSemanticModel {
13
14
  getTemplateChoicesOrThrow(templateId: DamlLfTemplateId): readonly DamlLfChoice[];
14
15
  /** Returns the record fields for a resolved type constructor reference. */
15
16
  getRecordFieldsOrThrow(reference: TypeConReference): readonly DamlLfField[];
17
+ /** Returns the complete resolved data type for a type constructor reference. */
18
+ getDataTypeOrThrow(reference: TypeConReference): DamlLfDataType;
16
19
  }
@@ -14,6 +14,10 @@ export class DamlLfSemanticModel {
14
14
  }
15
15
  /** Returns the record fields for a resolved type constructor reference. */
16
16
  getRecordFieldsOrThrow(reference) {
17
- return this.compilation.getTypeSymbolOrThrow(reference).definition.fields;
17
+ return this.getDataTypeOrThrow(reference).fields;
18
+ }
19
+ /** Returns the complete resolved data type for a type constructor reference. */
20
+ getDataTypeOrThrow(reference) {
21
+ return this.compilation.getTypeSymbolOrThrow(reference).definition;
18
22
  }
19
23
  }
@@ -629,6 +629,17 @@ function mapEventJson(value) {
629
629
  const row = mapSelectedProfileJsonRow(value, "__events");
630
630
  return row ?? undefined;
631
631
  }
632
+ function mapSelectedRelationJson(value, relation) {
633
+ const row = mapSelectedProfileJsonRow(value, relation);
634
+ return row ?? undefined;
635
+ }
636
+ function mapLogicalContractJson(value) {
637
+ if (value === null || value === undefined)
638
+ return undefined;
639
+ if (typeof value !== "object" || Array.isArray(value))
640
+ throw new Error("Invalid included __contracts row");
641
+ return value;
642
+ }
632
643
  function mapExerciseJson(value) {
633
644
  const raw = value;
634
645
  const row = mapSelectedProfileJsonRow(value, "__exercises");
@@ -641,8 +652,12 @@ function mapExerciseJson(value) {
641
652
  return {
642
653
  ...base,
643
654
  ...projections,
655
+ ...(raw.exerciseType === undefined ? {} : { exerciseType: mapSelectedRelationJson(raw.exerciseType, "__exercise_tpe") }),
656
+ ...(raw.contractType === undefined ? {} : { contractType: mapSelectedRelationJson(raw.contractType, "__contract_tpe") }),
644
657
  ...(raw.event === undefined ? {} : { event: raw.event === null ? null : mapEventJson(raw.event) ?? null }),
645
658
  ...(raw.transaction === undefined ? {} : { transaction: raw.transaction === null ? null : mapTransactionJson(raw.transaction) ?? null }),
659
+ ...(raw.package === undefined ? {} : { package: mapSelectedRelationJson(raw.package, "__packages") }),
660
+ ...(raw.contract === undefined ? {} : { contract: mapLogicalContractJson(raw.contract) }),
646
661
  };
647
662
  }
648
663
  function mapContractRow(row, include, json) {
@@ -69,16 +69,16 @@ function compileProfileIncludes(source, parentAlias, include, profile, addValue)
69
69
  const alias = `"${name}"`;
70
70
  const nested = compileProfileIncludes(edge.target, alias, options.include, profile, addValue);
71
71
  const metadata = pqsRelationMetadata[edge.target];
72
- const requested = options.select === undefined
73
- ? Object.entries(metadata.fields)
74
- : Object.entries(options.select).filter(([field, enabled]) => field !== "json" && enabled === true).map(([field]) => [field, metadata.fields[field]]);
72
+ const requested = compileIncludedFields(edge.target, options.select, alias, profile);
75
73
  const json = options.select?.json ?? {};
76
74
  const jsonSelections = Object.entries(json).map(([projectionName, projection]) => {
77
75
  if (!PqsSchemaProfileV1.jsonField(edge.target, projection.field))
78
76
  throw new Error(`${projection.field} is not a JSON field of ${edge.target}`);
79
77
  if (projection.path.length === 0 || projection.path.some((segment) => segment.length === 0))
80
78
  throw new Error(`${projectionName}.path must be a non-empty JSON path`);
81
- const column = metadata.fields[projection.field];
79
+ const column = edge.target === "__contracts"
80
+ ? projection.field === "payload" ? "payload" : undefined
81
+ : metadata.fields[projection.field];
82
82
  if (column === undefined)
83
83
  throw new Error(`${projection.field} is not a field of ${edge.target}`);
84
84
  const text = `${alias}."${column}" #>> ${addValue(projection.path)}::text[]`;
@@ -87,9 +87,7 @@ function compileProfileIncludes(source, parentAlias, include, profile, addValue)
87
87
  });
88
88
  if (requested.length === 0 && jsonSelections.length === 0)
89
89
  throw new Error(`Nested ${name}.select must include at least one field`);
90
- if (requested.some(([, column]) => column === undefined))
91
- throw new Error(`Nested ${name}.select references an unknown field`);
92
- const fields = requested.flatMap(([field, column]) => [`'${field}'`, `${alias}."${column}"`]);
90
+ const fields = requested.flatMap(([field, expression]) => [`'${field}'`, expression]);
93
91
  const nestedFields = nested.flatMap((selection) => {
94
92
  const match = /^(.*) as "([^"]+)"$/.exec(selection);
95
93
  return match === null ? [] : [`'${match[2]}'`, match[1]];
@@ -105,6 +103,36 @@ function compileProfileIncludes(source, parentAlias, include, profile, addValue)
105
103
  }
106
104
  return selected;
107
105
  }
106
+ function compileIncludedFields(target, select, alias, profile) {
107
+ if (target !== "__contracts") {
108
+ const metadata = pqsRelationMetadata[target];
109
+ const selected = select === undefined
110
+ ? Object.entries(metadata.fields)
111
+ : Object.entries(select).filter(([field, enabled]) => field !== "json" && enabled === true).map(([field]) => [field, metadata.fields[field]]);
112
+ if (selected.some(([, column]) => column === undefined))
113
+ throw new Error("Nested relation.select references an unknown field");
114
+ return selected.map(([field, column]) => [field, `${alias}."${column}"`]);
115
+ }
116
+ const selected = select === undefined
117
+ ? ["contractId", "templateId", "packageId", "payload", "witnesses", "createdEventOffset", "createdAt", "archivedEventOffset", "archivedAt", "active"]
118
+ : Object.entries(select).filter(([field, enabled]) => field !== "json" && enabled === true).map(([field]) => field);
119
+ const expressions = {
120
+ contractId: `${alias}."contract_id"`,
121
+ templateId: `jsonb_build_object('packageId', ${alias}."creation_package_id", 'moduleName', (select contract_type."module_name" from ${profile.relation("__contract_tpe")} contract_type where contract_type."pk" = ${alias}."tpe_pk"), 'entityName', (select contract_type."entity_name" from ${profile.relation("__contract_tpe")} contract_type where contract_type."pk" = ${alias}."tpe_pk"))`,
122
+ packageId: `${alias}."creation_package_id"`,
123
+ payload: `${alias}."payload"`,
124
+ witnesses: `${alias}."witnesses"`,
125
+ createdEventOffset: `${alias}."created_at_ix"::text`,
126
+ createdAt: `(select created_transaction."effective_at" from ${profile.relation("__transactions")} created_transaction where created_transaction."ix" = ${alias}."created_at_ix")`,
127
+ archivedEventOffset: `${alias}."archived_at_ix"::text`,
128
+ archivedAt: `(select archived_transaction."effective_at" from ${profile.relation("__transactions")} archived_transaction where archived_transaction."ix" = ${alias}."archived_at_ix")`,
129
+ active: `${alias}."archived_at_ix" is null`,
130
+ };
131
+ const requested = selected.map((field) => [field, expressions[field]]);
132
+ if (requested.some(([, expression]) => expression === undefined))
133
+ throw new Error("Nested contract.select references an unknown field");
134
+ return requested;
135
+ }
108
136
  function compilePhysicalOrderBy(relation, orderBy, alias) {
109
137
  if (orderBy === undefined)
110
138
  return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",