@distrohelena/canton-typescript-sdk 1.0.5 → 1.0.6
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.
|
@@ -120,20 +120,24 @@ function decodeProtobufRecord(record, descriptor, registry, path) {
|
|
|
120
120
|
for (const field of descriptor.fields) {
|
|
121
121
|
const sourceField = fields.find((candidate) => candidate.label === field.damlLabel);
|
|
122
122
|
if (sourceField === undefined) {
|
|
123
|
-
|
|
123
|
+
output[field.propertyName] = decodeMissingRecordField(field, fieldPath(path, field.propertyName));
|
|
124
|
+
continue;
|
|
124
125
|
}
|
|
125
126
|
output[field.propertyName] = decodeRequiredProtobufValue(sourceField.value, field.type, registry, fieldPath(path, field.propertyName));
|
|
126
127
|
}
|
|
127
|
-
if (fields.
|
|
128
|
+
if (fields.some((field) => !descriptor.fields.some((descriptorField) => descriptorField.damlLabel === field.label))) {
|
|
128
129
|
throw materializationError(path, "record contains an unexpected field");
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
else {
|
|
132
|
-
if (fields.length
|
|
133
|
+
if (fields.length > descriptor.fields.length) {
|
|
133
134
|
throw materializationError(path, "record has the wrong number of positional fields");
|
|
134
135
|
}
|
|
135
136
|
descriptor.fields.forEach((field, index) => {
|
|
136
|
-
|
|
137
|
+
const sourceField = fields[index];
|
|
138
|
+
output[field.propertyName] = sourceField === undefined
|
|
139
|
+
? decodeMissingRecordField(field, fieldPath(path, field.propertyName))
|
|
140
|
+
: decodeRequiredProtobufValue(sourceField.value, field.type, registry, fieldPath(path, field.propertyName));
|
|
137
141
|
});
|
|
138
142
|
}
|
|
139
143
|
return new daml_values_js_1.DamlRecord(output);
|
|
@@ -212,11 +216,13 @@ function decodeJsonTextMap(value, descriptor, registry, path) {
|
|
|
212
216
|
function decodeJsonRecord(value, descriptor, registry, path) {
|
|
213
217
|
const output = Object.create(null);
|
|
214
218
|
if (Array.isArray(value)) {
|
|
215
|
-
if (value.length
|
|
219
|
+
if (value.length > descriptor.fields.length) {
|
|
216
220
|
throw materializationError(path, "record has the wrong number of positional fields");
|
|
217
221
|
}
|
|
218
222
|
descriptor.fields.forEach((field, index) => {
|
|
219
|
-
output[field.propertyName] =
|
|
223
|
+
output[field.propertyName] = index >= value.length
|
|
224
|
+
? decodeMissingRecordField(field, fieldPath(path, field.propertyName))
|
|
225
|
+
: decodeDamlValue({ kind: "json", value: value[index] }, field.type, registry, fieldPath(path, field.propertyName));
|
|
220
226
|
});
|
|
221
227
|
return new daml_values_js_1.DamlRecord(output);
|
|
222
228
|
}
|
|
@@ -229,12 +235,19 @@ function decodeJsonRecord(value, descriptor, registry, path) {
|
|
|
229
235
|
}
|
|
230
236
|
for (const field of descriptor.fields) {
|
|
231
237
|
if (!Object.hasOwn(record, field.damlLabel)) {
|
|
232
|
-
|
|
238
|
+
output[field.propertyName] = decodeMissingRecordField(field, fieldPath(path, field.propertyName));
|
|
239
|
+
continue;
|
|
233
240
|
}
|
|
234
241
|
output[field.propertyName] = decodeDamlValue({ kind: "json", value: Reflect.get(record, field.damlLabel) }, field.type, registry, fieldPath(path, field.propertyName));
|
|
235
242
|
}
|
|
236
243
|
return new daml_values_js_1.DamlRecord(output);
|
|
237
244
|
}
|
|
245
|
+
function decodeMissingRecordField(field, path) {
|
|
246
|
+
if (field.type.kind === "optional") {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
throw materializationError(path, "required record field is absent");
|
|
250
|
+
}
|
|
238
251
|
function decodeJsonVariant(value, descriptor, registry, path) {
|
|
239
252
|
const envelope = requireObject(value, path, "variant");
|
|
240
253
|
const tag = requireString(Reflect.get(envelope, "tag"), path, "variant tag");
|
|
@@ -116,20 +116,24 @@ function decodeProtobufRecord(record, descriptor, registry, path) {
|
|
|
116
116
|
for (const field of descriptor.fields) {
|
|
117
117
|
const sourceField = fields.find((candidate) => candidate.label === field.damlLabel);
|
|
118
118
|
if (sourceField === undefined) {
|
|
119
|
-
|
|
119
|
+
output[field.propertyName] = decodeMissingRecordField(field, fieldPath(path, field.propertyName));
|
|
120
|
+
continue;
|
|
120
121
|
}
|
|
121
122
|
output[field.propertyName] = decodeRequiredProtobufValue(sourceField.value, field.type, registry, fieldPath(path, field.propertyName));
|
|
122
123
|
}
|
|
123
|
-
if (fields.
|
|
124
|
+
if (fields.some((field) => !descriptor.fields.some((descriptorField) => descriptorField.damlLabel === field.label))) {
|
|
124
125
|
throw materializationError(path, "record contains an unexpected field");
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
else {
|
|
128
|
-
if (fields.length
|
|
129
|
+
if (fields.length > descriptor.fields.length) {
|
|
129
130
|
throw materializationError(path, "record has the wrong number of positional fields");
|
|
130
131
|
}
|
|
131
132
|
descriptor.fields.forEach((field, index) => {
|
|
132
|
-
|
|
133
|
+
const sourceField = fields[index];
|
|
134
|
+
output[field.propertyName] = sourceField === undefined
|
|
135
|
+
? decodeMissingRecordField(field, fieldPath(path, field.propertyName))
|
|
136
|
+
: decodeRequiredProtobufValue(sourceField.value, field.type, registry, fieldPath(path, field.propertyName));
|
|
133
137
|
});
|
|
134
138
|
}
|
|
135
139
|
return new DamlRecord(output);
|
|
@@ -208,11 +212,13 @@ function decodeJsonTextMap(value, descriptor, registry, path) {
|
|
|
208
212
|
function decodeJsonRecord(value, descriptor, registry, path) {
|
|
209
213
|
const output = Object.create(null);
|
|
210
214
|
if (Array.isArray(value)) {
|
|
211
|
-
if (value.length
|
|
215
|
+
if (value.length > descriptor.fields.length) {
|
|
212
216
|
throw materializationError(path, "record has the wrong number of positional fields");
|
|
213
217
|
}
|
|
214
218
|
descriptor.fields.forEach((field, index) => {
|
|
215
|
-
output[field.propertyName] =
|
|
219
|
+
output[field.propertyName] = index >= value.length
|
|
220
|
+
? decodeMissingRecordField(field, fieldPath(path, field.propertyName))
|
|
221
|
+
: decodeDamlValue({ kind: "json", value: value[index] }, field.type, registry, fieldPath(path, field.propertyName));
|
|
216
222
|
});
|
|
217
223
|
return new DamlRecord(output);
|
|
218
224
|
}
|
|
@@ -225,12 +231,19 @@ function decodeJsonRecord(value, descriptor, registry, path) {
|
|
|
225
231
|
}
|
|
226
232
|
for (const field of descriptor.fields) {
|
|
227
233
|
if (!Object.hasOwn(record, field.damlLabel)) {
|
|
228
|
-
|
|
234
|
+
output[field.propertyName] = decodeMissingRecordField(field, fieldPath(path, field.propertyName));
|
|
235
|
+
continue;
|
|
229
236
|
}
|
|
230
237
|
output[field.propertyName] = decodeDamlValue({ kind: "json", value: Reflect.get(record, field.damlLabel) }, field.type, registry, fieldPath(path, field.propertyName));
|
|
231
238
|
}
|
|
232
239
|
return new DamlRecord(output);
|
|
233
240
|
}
|
|
241
|
+
function decodeMissingRecordField(field, path) {
|
|
242
|
+
if (field.type.kind === "optional") {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
throw materializationError(path, "required record field is absent");
|
|
246
|
+
}
|
|
234
247
|
function decodeJsonVariant(value, descriptor, registry, path) {
|
|
235
248
|
const envelope = requireObject(value, path, "variant");
|
|
236
249
|
const tag = requireString(Reflect.get(envelope, "tag"), path, "variant tag");
|