@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
|
@@ -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
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
numericScale,
|
|
41
|
-
...(lhs.typeConReference === undefined
|
|
36
|
+
return new DamlLfType({
|
|
37
|
+
builtinType: lhs.builtinType,
|
|
38
|
+
...(numericScale === undefined
|
|
39
|
+
? lhs.numericScale === undefined
|
|
42
40
|
? {}
|
|
43
|
-
: {
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
...(
|
|
70
|
+
...(numericScale === undefined
|
|
67
71
|
? {}
|
|
68
|
-
: {
|
|
69
|
-
|
|
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
|
|
107
|
-
?
|
|
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
|
-
|
|
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.
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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 "";
|