@distrohelena/canton-typescript-sdk 0.1.25 → 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.
@@ -7,7 +7,6 @@ export type AnalyzedDamlPrimitiveType = {
7
7
  };
8
8
  export type AnalyzedDamlContractIdType = {
9
9
  readonly kind: "contractId";
10
- readonly contract: AnalyzedDamlType;
11
10
  };
12
11
  export type AnalyzedDamlOptionalType = {
13
12
  readonly kind: "optional";
@@ -128,9 +128,9 @@ class AnalyzedDamlTypeBuilder {
128
128
  numericScale: type.numericScale,
129
129
  });
130
130
  case DamlLfBuiltinType.contractId:
131
+ this.assertArgumentCountOrThrow(type, 1, context);
131
132
  return Object.freeze({
132
133
  kind: "contractId",
133
- contract: this.buildUnaryArgumentOrThrow(type, context),
134
134
  });
135
135
  case DamlLfBuiltinType.optional:
136
136
  return Object.freeze({
@@ -139,9 +139,7 @@ export class NamedTypeEmitter {
139
139
  case "namedReference":
140
140
  yield type;
141
141
  return;
142
- case "contractId":
143
- yield* this.getNamedReferences(type.contract);
144
- return;
142
+ case "contractId": return;
145
143
  case "optional":
146
144
  case "list":
147
145
  yield* this.getNamedReferences(type.element);
@@ -405,9 +403,7 @@ export class NamedTypeEmitter {
405
403
  }
406
404
  return;
407
405
  }
408
- case "contractId":
409
- yield* this.getRuntimePrimitiveTypes(type.contract);
410
- return;
406
+ case "contractId": return;
411
407
  case "optional":
412
408
  case "list":
413
409
  yield* this.getRuntimePrimitiveTypes(type.element);
@@ -186,7 +186,7 @@ export class SupportFileEmitter {
186
186
  case "primitive":
187
187
  return `{ kind: "primitive", primitive: ${JSON.stringify(type.builtinType)}${type.numericScale === undefined ? "" : `, numericScale: ${type.numericScale}`} }`;
188
188
  case "contractId":
189
- return `{ kind: "contractId", contract: ${this.emitDescriptor(type.contract)} }`;
189
+ return '{ kind: "contractId" }';
190
190
  case "optional":
191
191
  return `{ kind: "optional", element: ${this.emitDescriptor(type.element)} }`;
192
192
  case "list":
@@ -195,7 +195,7 @@ export class TemplateBindingEmitter {
195
195
  case "primitive":
196
196
  return `{ kind: "primitive", primitive: ${JSON.stringify(type.builtinType)}${type.numericScale === undefined ? "" : `, numericScale: ${type.numericScale}`} }`;
197
197
  case "contractId":
198
- return `{ kind: "contractId", contract: ${this.emitDescriptor(type.contract)} }`;
198
+ return '{ kind: "contractId" }';
199
199
  case "optional":
200
200
  return `{ kind: "optional", element: ${this.emitDescriptor(type.element)} }`;
201
201
  case "list":
@@ -255,13 +255,17 @@ export class TemplateBindingEmitter {
255
255
  if ("kind" in type) {
256
256
  return type;
257
257
  }
258
- const arguments_ = type.typeArguments.map((argument) => this.normalizeType(argument));
259
- if (type.typeConReference !== undefined) {
258
+ else if (type.builtinType === DamlLfBuiltinType.contractId) {
259
+ if (type.typeArguments.length !== 1) {
260
+ throw new Error("DAML ContractId requires exactly one type argument");
261
+ }
262
+ return { kind: "contractId" };
263
+ }
264
+ else if (type.typeConReference !== undefined) {
260
265
  return { kind: "namedReference", identity: type.typeConReference };
261
266
  }
267
+ const arguments_ = type.typeArguments.map((argument) => this.normalizeType(argument));
262
268
  switch (type.builtinType) {
263
- case DamlLfBuiltinType.contractId:
264
- return { kind: "contractId", contract: arguments_[0] ?? { kind: "primitive", builtinType: DamlLfBuiltinType.text } };
265
269
  case DamlLfBuiltinType.optional:
266
270
  return { kind: "optional", element: arguments_[0] ?? { kind: "primitive", builtinType: DamlLfBuiltinType.text } };
267
271
  case DamlLfBuiltinType.list:
@@ -345,9 +349,7 @@ export class TemplateBindingEmitter {
345
349
  case "namedReference":
346
350
  yield type;
347
351
  return;
348
- case "contractId":
349
- yield* this.walkNamedReferences(type.contract);
350
- return;
352
+ case "contractId": return;
351
353
  case "optional":
352
354
  case "list":
353
355
  yield* this.walkNamedReferences(type.element);
@@ -2,13 +2,13 @@ import { DamlLfBuiltinType } from "../../daml-lf/model/daml-lf-builtin-type.js";
2
2
  const typeScriptKeywords = new Set([
3
3
  "as", "async", "await", "break", "case", "catch", "class", "const", "continue",
4
4
  "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false",
5
- "finally", "for", "from", "function", "get", "if", "implements", "import", "in",
5
+ "finally", "for", "from", "function", "if", "implements", "import", "in",
6
6
  "instanceof", "interface", "let", "new", "null", "of", "package", "private", "protected",
7
7
  "public", "return", "set", "static", "super", "switch", "this", "throw", "true", "try",
8
8
  "type", "typeof", "undefined", "var", "void", "while", "with", "yield",
9
9
  ]);
10
10
  const damlTemplateMemberNames = new Set([
11
- "constructor", "get", "contractId", "templateId", "create", "decodeCreatedEvent",
11
+ "constructor", "contractId", "templateId", "create", "decodeCreatedEvent",
12
12
  "decodeExercisedEvent",
13
13
  ]);
14
14
  const reservedTypeNames = new Set(["DamlTemplate"]);
@@ -2,5 +2,5 @@
2
2
  export declare class DamlTemplate {
3
3
  #private;
4
4
  constructor(contractId: string);
5
- get(): string;
5
+ get contractId(): string;
6
6
  }
@@ -4,7 +4,7 @@ export class DamlTemplate {
4
4
  constructor(contractId) {
5
5
  this.#contractId = contractId;
6
6
  }
7
- get() {
7
+ get contractId() {
8
8
  return this.#contractId;
9
9
  }
10
10
  }
@@ -12,7 +12,7 @@ export type DamlPrimitiveDescriptor = {
12
12
  };
13
13
  export type DamlContractIdDescriptor = {
14
14
  readonly kind: "contractId";
15
- readonly contract: DamlTypeDescriptor;
15
+ readonly contract?: DamlTypeDescriptor;
16
16
  };
17
17
  export type DamlOptionalDescriptor = {
18
18
  readonly kind: "optional";
@@ -1,5 +1,6 @@
1
1
  import { DamlLfResolutionException } from "./errors/daml-lf-resolution.exception.js";
2
2
  import { DamlLfSemanticException } from "./errors/daml-lf-semantic.exception.js";
3
+ import { DamlLfBuiltinType } from "./model/daml-lf-builtin-type.js";
3
4
  import { DamlLfDataType } from "./model/daml-lf-data-type.js";
4
5
  import { DamlLfTemplate } from "./model/daml-lf-template.js";
5
6
  import { DamlLfValueDefinition } from "./model/daml-lf-value-definition.js";
@@ -122,6 +123,12 @@ export class DamlLfCompilation {
122
123
  }
123
124
  }
124
125
  validateTypeOrThrow(type) {
126
+ if (type.builtinType === DamlLfBuiltinType.contractId) {
127
+ if (type.typeArguments.length !== 1) {
128
+ throw new DamlLfSemanticException("builtin 'contractId' requires 1 type argument");
129
+ }
130
+ return;
131
+ }
125
132
  for (const typeArgument of type.typeArguments) {
126
133
  this.validateTypeOrThrow(typeArgument);
127
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",