@distrohelena/canton-typescript-sdk 1.0.4 → 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.
@@ -140,7 +140,7 @@ class TemplateBindingEmitter {
140
140
  `export class ${binding.className} extends ${this.getSdkName("DamlTemplate", runtimeWrapperTypeNames)} implements ${binding.createFieldsTypeName} {`,
141
141
  ` public static readonly templateId = ${JSON.stringify(binding.templateIdLiteral)};`,
142
142
  ...(binding.packageName === undefined ? [] : [` public static readonly packageName = ${JSON.stringify(binding.packageName)};`]),
143
- ` private static readonly descriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitTemplateDescriptor(binding)};`,
143
+ ` public static readonly descriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitTemplateDescriptor(binding)};`,
144
144
  "",
145
145
  ...binding.createFields.map((field) => ` public readonly ${field.propertyName}: ${field.typeName};`),
146
146
  ...(binding.createFields.length === 0 ? [] : [""]),
@@ -176,8 +176,8 @@ class TemplateBindingEmitter {
176
176
  emitChoiceEventClass(binding, choice, runtimeWrapperTypeNames) {
177
177
  return [
178
178
  `export class ${choice.exercisedEventTypeName} {`,
179
- ` private static readonly argumentDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.parameterType)};`,
180
- ` private static readonly resultDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.returnType)};`,
179
+ ` public static readonly argumentDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.parameterType)};`,
180
+ ` public static readonly resultDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.returnType)};`,
181
181
  "",
182
182
  ` public readonly choiceName = ${JSON.stringify(choice.name)} as const;`,
183
183
  " public readonly contractId: string;",
@@ -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
- throw materializationError(fieldPath(path, field.propertyName), "required record field is absent");
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.length !== descriptor.fields.length) {
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 !== descriptor.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
- output[field.propertyName] = decodeRequiredProtobufValue(fields[index]?.value, field.type, registry, fieldPath(path, field.propertyName));
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 !== descriptor.fields.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] = decodeDamlValue({ kind: "json", value: value[index] }, field.type, registry, fieldPath(path, 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
- throw materializationError(fieldPath(path, field.propertyName), "required record field is absent");
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");
@@ -137,7 +137,7 @@ export class TemplateBindingEmitter {
137
137
  `export class ${binding.className} extends ${this.getSdkName("DamlTemplate", runtimeWrapperTypeNames)} implements ${binding.createFieldsTypeName} {`,
138
138
  ` public static readonly templateId = ${JSON.stringify(binding.templateIdLiteral)};`,
139
139
  ...(binding.packageName === undefined ? [] : [` public static readonly packageName = ${JSON.stringify(binding.packageName)};`]),
140
- ` private static readonly descriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitTemplateDescriptor(binding)};`,
140
+ ` public static readonly descriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitTemplateDescriptor(binding)};`,
141
141
  "",
142
142
  ...binding.createFields.map((field) => ` public readonly ${field.propertyName}: ${field.typeName};`),
143
143
  ...(binding.createFields.length === 0 ? [] : [""]),
@@ -173,8 +173,8 @@ export class TemplateBindingEmitter {
173
173
  emitChoiceEventClass(binding, choice, runtimeWrapperTypeNames) {
174
174
  return [
175
175
  `export class ${choice.exercisedEventTypeName} {`,
176
- ` private static readonly argumentDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.parameterType)};`,
177
- ` private static readonly resultDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.returnType)};`,
176
+ ` public static readonly argumentDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.parameterType)};`,
177
+ ` public static readonly resultDescriptor: ${this.getSdkName("DamlTypeDescriptor", runtimeWrapperTypeNames)} = ${this.emitDescriptor(choice.returnType)};`,
178
178
  "",
179
179
  ` public readonly choiceName = ${JSON.stringify(choice.name)} as const;`,
180
180
  " public readonly contractId: string;",
@@ -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
- throw materializationError(fieldPath(path, field.propertyName), "required record field is absent");
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.length !== descriptor.fields.length) {
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 !== descriptor.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
- output[field.propertyName] = decodeRequiredProtobufValue(fields[index]?.value, field.type, registry, fieldPath(path, field.propertyName));
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 !== descriptor.fields.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] = decodeDamlValue({ kind: "json", value: value[index] }, field.type, registry, fieldPath(path, 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
- throw materializationError(fieldPath(path, field.propertyName), "required record field is absent");
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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",