@distrohelena/canton-typescript-sdk 0.1.12 → 0.1.13

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.
@@ -1,10 +1,11 @@
1
+ import type { TemplateId } from "../../query/model-types.js";
1
2
  export declare class CommandInspectionContract {
2
- readonly templateId?: string;
3
+ readonly templateId?: TemplateId;
3
4
  readonly contractId: string;
4
5
  readonly contractKey?: unknown;
5
6
  constructor(init: {
6
7
  contractId: string;
7
- templateId?: string;
8
+ templateId?: TemplateId;
8
9
  contractKey?: unknown;
9
10
  });
10
11
  }
@@ -1,12 +1,14 @@
1
+ import { DamlRecord } from "../daml-values.js";
2
+ import type { TemplateId } from "../../../query/model-types.js";
1
3
  export declare class CreateAndExerciseCommand {
2
- readonly templateId: string;
3
- readonly payload: Record<string, unknown>;
4
+ readonly templateId: TemplateId;
5
+ readonly createArguments: DamlRecord;
4
6
  readonly choice: string;
5
- readonly argument: unknown;
7
+ readonly choiceArgument: unknown;
6
8
  constructor(init: {
7
- templateId: string;
8
- payload: Record<string, unknown>;
9
+ templateId: TemplateId;
10
+ createArguments: DamlRecord;
9
11
  choice: string;
10
- argument: unknown;
12
+ choiceArgument: unknown;
11
13
  });
12
14
  }
@@ -1,19 +1,23 @@
1
1
  import { ValidationError } from "../../errors/validation-error.js";
2
+ import { DamlRecord } from "../daml-values.js";
2
3
  export class CreateAndExerciseCommand {
3
4
  templateId;
4
- payload;
5
+ createArguments;
5
6
  choice;
6
- argument;
7
+ choiceArgument;
7
8
  constructor(init) {
8
- if (!init.templateId) {
9
+ if (!init.templateId?.moduleName || !init.templateId.entityName) {
9
10
  throw new ValidationError("create-and-exercise commands require a templateId");
10
11
  }
12
+ else if (!(init.createArguments instanceof DamlRecord)) {
13
+ throw new ValidationError("create-and-exercise commands require DamlRecord createArguments");
14
+ }
11
15
  else if (!init.choice) {
12
16
  throw new ValidationError("create-and-exercise commands require a choice");
13
17
  }
14
18
  this.templateId = init.templateId;
15
- this.payload = init.payload;
19
+ this.createArguments = init.createArguments;
16
20
  this.choice = init.choice;
17
- this.argument = init.argument;
21
+ this.choiceArgument = init.choiceArgument;
18
22
  }
19
23
  }
@@ -1,8 +1,10 @@
1
+ import { DamlRecord } from "../daml-values.js";
2
+ import type { TemplateId } from "../../../query/model-types.js";
1
3
  export declare class CreateCommand {
2
- readonly templateId: string;
3
- readonly payload: Record<string, unknown>;
4
+ readonly templateId: TemplateId;
5
+ readonly createArguments: DamlRecord;
4
6
  constructor(init: {
5
- templateId: string;
6
- payload: Record<string, unknown>;
7
+ templateId: TemplateId;
8
+ createArguments: DamlRecord;
7
9
  });
8
10
  }
@@ -1,12 +1,16 @@
1
1
  import { ValidationError } from "../../errors/validation-error.js";
2
+ import { DamlRecord } from "../daml-values.js";
2
3
  export class CreateCommand {
3
4
  templateId;
4
- payload;
5
+ createArguments;
5
6
  constructor(init) {
6
- if (!init.templateId) {
7
+ if (!init.templateId?.moduleName || !init.templateId.entityName) {
7
8
  throw new ValidationError("create commands require a templateId");
8
9
  }
10
+ else if (!(init.createArguments instanceof DamlRecord)) {
11
+ throw new ValidationError("create commands require DamlRecord createArguments");
12
+ }
9
13
  this.templateId = init.templateId;
10
- this.payload = init.payload;
14
+ this.createArguments = init.createArguments;
11
15
  }
12
16
  }
@@ -1,12 +1,13 @@
1
+ import type { TemplateId } from "../../../query/model-types.js";
1
2
  export declare class ExerciseByKeyCommand {
2
- readonly templateId: string;
3
+ readonly templateId: TemplateId;
3
4
  readonly contractKey: unknown;
4
5
  readonly choice: string;
5
- readonly argument: unknown;
6
+ readonly choiceArgument: unknown;
6
7
  constructor(init: {
7
- templateId: string;
8
+ templateId: TemplateId;
8
9
  contractKey: unknown;
9
10
  choice: string;
10
- argument: unknown;
11
+ choiceArgument: unknown;
11
12
  });
12
13
  }
@@ -3,9 +3,9 @@ export class ExerciseByKeyCommand {
3
3
  templateId;
4
4
  contractKey;
5
5
  choice;
6
- argument;
6
+ choiceArgument;
7
7
  constructor(init) {
8
- if (!init.templateId) {
8
+ if (!init.templateId?.moduleName || !init.templateId.entityName) {
9
9
  throw new ValidationError("exercise-by-key commands require a templateId");
10
10
  }
11
11
  else if (init.contractKey === undefined) {
@@ -17,6 +17,6 @@ export class ExerciseByKeyCommand {
17
17
  this.templateId = init.templateId;
18
18
  this.contractKey = init.contractKey;
19
19
  this.choice = init.choice;
20
- this.argument = init.argument;
20
+ this.choiceArgument = init.choiceArgument;
21
21
  }
22
22
  }
@@ -1,12 +1,13 @@
1
+ import type { TemplateId } from "../../../query/model-types.js";
1
2
  export declare class ExerciseCommand {
2
- readonly templateId: string;
3
+ readonly templateId: TemplateId;
3
4
  readonly contractId: string;
4
5
  readonly choice: string;
5
- readonly argument: unknown;
6
+ readonly choiceArgument: unknown;
6
7
  constructor(init: {
7
- templateId: string;
8
+ templateId: TemplateId;
8
9
  contractId: string;
9
10
  choice: string;
10
- argument: unknown;
11
+ choiceArgument: unknown;
11
12
  });
12
13
  }
@@ -3,9 +3,9 @@ export class ExerciseCommand {
3
3
  templateId;
4
4
  contractId;
5
5
  choice;
6
- argument;
6
+ choiceArgument;
7
7
  constructor(init) {
8
- if (!init.templateId) {
8
+ if (!init.templateId?.moduleName || !init.templateId.entityName) {
9
9
  throw new ValidationError("exercise commands require a templateId");
10
10
  }
11
11
  else if (!init.contractId) {
@@ -17,6 +17,6 @@ export class ExerciseCommand {
17
17
  this.templateId = init.templateId;
18
18
  this.contractId = init.contractId;
19
19
  this.choice = init.choice;
20
- this.argument = init.argument;
20
+ this.choiceArgument = init.choiceArgument;
21
21
  }
22
22
  }
@@ -1,18 +1,20 @@
1
+ import type { DamlRecord } from "./daml-values.js";
2
+ import type { TemplateId } from "../../query/model-types.js";
1
3
  export declare class SdkCommand {
2
4
  readonly type: string;
3
- readonly templateId?: string;
5
+ readonly templateId?: TemplateId;
4
6
  readonly contractId?: string;
5
7
  readonly contractKey?: unknown;
6
8
  readonly choice?: string;
7
- readonly createArguments?: Record<string, unknown>;
9
+ readonly createArguments?: DamlRecord;
8
10
  readonly choiceArgument?: unknown;
9
11
  constructor(init: {
10
12
  type: string;
11
- templateId?: string;
13
+ templateId?: TemplateId;
12
14
  contractId?: string;
13
15
  contractKey?: unknown;
14
16
  choice?: string;
15
- createArguments?: Record<string, unknown>;
17
+ createArguments?: DamlRecord;
16
18
  choiceArgument?: unknown;
17
19
  });
18
20
  }
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { PqsQueryError } from "./query/errors/pqs-query-error.js";
7
7
  export { PqsSchemaProfileError } from "./query/errors/pqs-schema-profile-error.js";
8
8
  export type { CantonManagerOptions, PqsQueryOptions, QueryCacheOptions, } from "./query/canton-manager-options.js";
9
9
  export type { QueryCacheStore } from "./query/cache/query-cache-store.js";
10
- export type { ContractFindManyArgs, ContractFindUniqueArgs, ContractCountArgs, ContractRow, ContractTypeRow, EventRow, ExerciseRow, ExerciseTypeRow, PackageRow, TransactionRow, WatermarkRow, RowWhere, RowSelect, RowOrderBy, } from "./query/model-types.js";
10
+ export type { ContractFindManyArgs, ContractFindUniqueArgs, ContractCountArgs, ContractRow, TemplateId, ContractTypeRow, EventRow, ExerciseRow, ExerciseTypeRow, PackageRow, TransactionRow, WatermarkRow, RowWhere, RowSelect, RowOrderBy, } from "./query/model-types.js";
11
11
  export type { QueryClient, QueryDelegate, QueryCollectionDelegate } from "./query/query-client.js";
12
12
  export { CantonHashingClient } from "./client/canton-hashing-client.js";
13
13
  export { CantonClientOptions } from "./client/canton-client-options.js";
@@ -15,7 +15,7 @@ function mapCanonicalCommand(command) {
15
15
  return {
16
16
  kind: "create",
17
17
  templateId: command.templateId,
18
- payload: command.payload,
18
+ createArguments: mapCanonicalRecord(command.createArguments),
19
19
  };
20
20
  }
21
21
  else if (command instanceof ExerciseCommand) {
@@ -24,7 +24,7 @@ function mapCanonicalCommand(command) {
24
24
  templateId: command.templateId,
25
25
  contractId: command.contractId,
26
26
  choice: command.choice,
27
- argument: command.argument,
27
+ choiceArgument: command.choiceArgument,
28
28
  };
29
29
  }
30
30
  else if (command instanceof ExerciseByKeyCommand) {
@@ -33,17 +33,23 @@ function mapCanonicalCommand(command) {
33
33
  templateId: command.templateId,
34
34
  contractKey: command.contractKey,
35
35
  choice: command.choice,
36
- argument: command.argument,
36
+ choiceArgument: command.choiceArgument,
37
37
  };
38
38
  }
39
39
  else if (command instanceof CreateAndExerciseCommand) {
40
40
  return {
41
41
  kind: "createAndExercise",
42
42
  templateId: command.templateId,
43
- payload: command.payload,
43
+ createArguments: mapCanonicalRecord(command.createArguments),
44
44
  choice: command.choice,
45
- argument: command.argument,
45
+ choiceArgument: command.choiceArgument,
46
46
  };
47
47
  }
48
48
  return {};
49
49
  }
50
+ function mapCanonicalRecord(record) {
51
+ return {
52
+ fields: record.fields,
53
+ recordId: record.recordId ?? null,
54
+ };
55
+ }
@@ -3,10 +3,11 @@ import { CampaignExecutableAction } from "../campaign/campaign-runner.js";
3
3
  import { ResolvedDeclarativeChoiceTarget } from "../targets/target.js";
4
4
  import { DamlTestingCatalog } from "./daml-testing-catalog.js";
5
5
  import { DamlTestingValue } from "./daml-value-arbitrary.js";
6
+ import type { TemplateId } from "../../query/model-types.js";
6
7
  export interface DeclarativeChoiceAction extends CampaignExecutableAction {
7
8
  readonly argument: DamlTestingValue;
8
9
  readonly choice: string;
9
- readonly templateId: string;
10
+ readonly templateId: TemplateId;
10
11
  }
11
12
  /**
12
13
  * Builds a well-typed, actor-routed automatic choice input from declarative
@@ -7,7 +7,7 @@ import { createDamlValueArbitrary } from "./daml-value-arbitrary.js";
7
7
  * in the runtime adapter.
8
8
  */
9
9
  export function createDeclarativeChoiceActionArbitrary(catalog, target, options = {}) {
10
- const choice = catalog.getChoice(target.templateId, target.choice);
10
+ const choice = catalog.getChoice(formatTemplateId(target.templateId), target.choice);
11
11
  if (choice === undefined) {
12
12
  throw new TestingConfigurationError(`Declarative target '${target.key}' does not exist in the DAML catalog.`);
13
13
  }
@@ -25,3 +25,6 @@ export function createDeclarativeChoiceActionArbitrary(catalog, target, options
25
25
  templateId: target.templateId,
26
26
  }));
27
27
  }
28
+ function formatTemplateId(templateId) {
29
+ return `${templateId.packageId}:${templateId.moduleName}:${templateId.entityName}`;
30
+ }
@@ -3,9 +3,10 @@ import { CampaignExecutableAction } from "../campaign/campaign-runner.js";
3
3
  import { ResolvedDeclarativeCreateTarget } from "../targets/target.js";
4
4
  import { DamlTestingCatalog } from "./daml-testing-catalog.js";
5
5
  import { DamlTestingValue } from "./daml-value-arbitrary.js";
6
+ import type { TemplateId } from "../../query/model-types.js";
6
7
  export interface DeclarativeCreateAction extends CampaignExecutableAction {
7
8
  readonly payload: Readonly<Record<string, DamlTestingValue>>;
8
- readonly templateId: string;
9
+ readonly templateId: TemplateId;
9
10
  }
10
11
  export interface DeclarativeCreateActionGenerationOptions {
11
12
  readonly fieldArbitraries?: Readonly<Record<string, fc.Arbitrary<DamlTestingValue>>>;
@@ -7,7 +7,7 @@ import { createDamlValueArbitrary } from "./daml-value-arbitrary.js";
7
7
  * adapter.
8
8
  */
9
9
  export function createDeclarativeCreateActionArbitrary(catalog, target, options = {}) {
10
- const template = catalog.getTemplate(target.templateId);
10
+ const template = catalog.getTemplate(formatTemplateId(target.templateId));
11
11
  if (template === undefined) {
12
12
  throw new TestingConfigurationError(`Declarative target '${target.key}' does not exist in the DAML catalog.`);
13
13
  }
@@ -32,3 +32,6 @@ export function createDeclarativeCreateActionArbitrary(catalog, target, options
32
32
  templateId: target.templateId,
33
33
  }));
34
34
  }
35
+ function formatTemplateId(templateId) {
36
+ return `${templateId.packageId}:${templateId.moduleName}:${templateId.entityName}`;
37
+ }
@@ -1,5 +1,6 @@
1
1
  import { CreateCommand } from "../../core/types/commands/create-command.js";
2
2
  import { ExerciseCommand } from "../../core/types/commands/exercise-command.js";
3
+ import { DamlRecord } from "../../core/types/daml-values.js";
3
4
  import { SubmitCommandRequest } from "../../core/types/requests/submit-command-request.js";
4
5
  import { TestingConfigurationError } from "../errors/testing-configuration-error.js";
5
6
  import { toCampaignMetricOutcome, } from "./canton-test-runtime.js";
@@ -15,7 +16,7 @@ export async function executeDeclarativeActionAsync(init) {
15
16
  ? await createExerciseCommandAsync(init.action, init.resolveContractIdAsync)
16
17
  : new CreateCommand({
17
18
  templateId: init.action.templateId,
18
- payload: { ...init.action.payload },
19
+ createArguments: new DamlRecord({ ...init.action.payload }),
19
20
  });
20
21
  return toCampaignMetricOutcome(await init.runtime.submitAndWaitAsync(init.action.actor, new SubmitCommandRequest({
21
22
  applicationId: init.applicationId,
@@ -36,6 +37,6 @@ async function createExerciseCommandAsync(action, resolveContractIdAsync) {
36
37
  templateId: action.templateId,
37
38
  contractId,
38
39
  choice: action.choice,
39
- argument: action.argument,
40
+ choiceArgument: action.argument,
40
41
  });
41
42
  }
@@ -1,24 +1,25 @@
1
1
  import { DamlTestingCatalog } from "../daml/daml-testing-catalog.js";
2
+ import type { TemplateId } from "../../query/model-types.js";
2
3
  export interface TemplateTarget {
3
4
  readonly allChoices?: true;
4
5
  readonly actors: readonly string[];
5
6
  readonly choices: readonly string[];
6
7
  readonly kind: "template";
7
- readonly templateId: string;
8
+ readonly templateId: TemplateId;
8
9
  }
9
10
  export interface TemplateCreateTarget {
10
11
  readonly actors: readonly string[];
11
12
  readonly kind: "template-create";
12
- readonly templateId: string;
13
+ readonly templateId: TemplateId;
13
14
  }
14
15
  export interface ExcludedChoiceTarget {
15
16
  readonly choice: string;
16
17
  readonly kind: "exclude-choice";
17
- readonly templateId: string;
18
+ readonly templateId: TemplateId;
18
19
  }
19
20
  export interface ExcludedTemplateTarget {
20
21
  readonly kind: "exclude-template";
21
- readonly templateId: string;
22
+ readonly templateId: TemplateId;
22
23
  }
23
24
  export interface TemplateTargetBuilder {
24
25
  allChoices(): TemplateTarget;
@@ -30,20 +31,20 @@ export interface ResolvedDeclarativeChoiceTarget {
30
31
  readonly actors: readonly string[];
31
32
  readonly choice: string;
32
33
  readonly key: string;
33
- readonly templateId: string;
34
+ readonly templateId: TemplateId;
34
35
  }
35
36
  export interface ResolvedDeclarativeCreateTarget {
36
37
  readonly actors: readonly string[];
37
38
  readonly key: string;
38
39
  readonly kind: "create";
39
- readonly templateId: string;
40
+ readonly templateId: TemplateId;
40
41
  }
41
42
  export type ResolvedDeclarativeTarget = ResolvedDeclarativeChoiceTarget | ResolvedDeclarativeCreateTarget;
42
- export declare function targetTemplate(templateId: string): TemplateTargetBuilder;
43
+ export declare function targetTemplate(templateId: TemplateId): TemplateTargetBuilder;
43
44
  /** Builds one immutable declarative template-choice target without a builder chain. */
44
- export declare function targetChoice(templateId: string, choice: string, actors: readonly string[]): TemplateTarget;
45
+ export declare function targetChoice(templateId: TemplateId, choice: string, actors: readonly string[]): TemplateTarget;
45
46
  /** Builds one immutable declarative contract-create target without a builder chain. */
46
- export declare function targetCreate(templateId: string, actors: readonly string[]): TemplateCreateTarget;
47
- export declare function excludeChoice(templateId: string, choice: string): ExcludedChoiceTarget;
48
- export declare function excludeTemplate(templateId: string): ExcludedTemplateTarget;
47
+ export declare function targetCreate(templateId: TemplateId, actors: readonly string[]): TemplateCreateTarget;
48
+ export declare function excludeChoice(templateId: TemplateId, choice: string): ExcludedChoiceTarget;
49
+ export declare function excludeTemplate(templateId: TemplateId): ExcludedTemplateTarget;
49
50
  export declare function resolveDeclarativeTargets(catalog: DamlTestingCatalog, descriptors: readonly (TemplateTarget | TemplateCreateTarget | ExcludedChoiceTarget | ExcludedTemplateTarget)[]): readonly ResolvedDeclarativeTarget[];
@@ -67,50 +67,50 @@ export function resolveDeclarativeTargets(catalog, descriptors) {
67
67
  if (descriptor.kind === "template") {
68
68
  continue;
69
69
  }
70
- const template = catalog.getTemplate(descriptor.templateId);
70
+ const template = catalog.getTemplate(formatTemplateId(descriptor.templateId));
71
71
  if (template === undefined) {
72
- throw new TestingConfigurationError(`Declarative target '${descriptor.templateId}' is absent from the DAML catalog.`);
72
+ throw new TestingConfigurationError(`Declarative target '${formatTemplateId(descriptor.templateId)}' is absent from the DAML catalog.`);
73
73
  }
74
74
  else if (descriptor.kind === "exclude-choice"
75
75
  && !template.choices.includes(descriptor.choice)) {
76
- throw new TestingConfigurationError(`Declarative target '${descriptor.templateId}:${descriptor.choice}' is absent from the DAML catalog.`);
76
+ throw new TestingConfigurationError(`Declarative target '${formatTemplateId(descriptor.templateId)}:${descriptor.choice}' is absent from the DAML catalog.`);
77
77
  }
78
78
  }
79
79
  const excludedTemplates = new Set(descriptors
80
80
  .filter((descriptor) => descriptor.kind === "exclude-template")
81
- .map((descriptor) => descriptor.templateId));
81
+ .map((descriptor) => formatTemplateId(descriptor.templateId)));
82
82
  const excluded = new Set(descriptors
83
83
  .filter((descriptor) => descriptor.kind === "exclude-choice")
84
- .map((descriptor) => `${descriptor.templateId}:${descriptor.choice}`));
84
+ .map((descriptor) => `${formatTemplateId(descriptor.templateId)}:${descriptor.choice}`));
85
85
  return descriptors
86
86
  .filter((descriptor) => descriptor.kind === "template" || descriptor.kind === "template-create")
87
87
  .flatMap((descriptor) => {
88
- const template = catalog.getTemplate(descriptor.templateId);
88
+ const template = catalog.getTemplate(formatTemplateId(descriptor.templateId));
89
89
  if (template === undefined) {
90
- throw new TestingConfigurationError(`Declarative target '${descriptor.templateId}' is absent from the DAML catalog.`);
90
+ throw new TestingConfigurationError(`Declarative target '${formatTemplateId(descriptor.templateId)}' is absent from the DAML catalog.`);
91
91
  }
92
92
  else if (descriptor.kind === "template-create") {
93
93
  return [Object.freeze({
94
- key: `${descriptor.templateId}:create`,
94
+ key: `${formatTemplateId(descriptor.templateId)}:create`,
95
95
  templateId: descriptor.templateId,
96
96
  actors: descriptor.actors,
97
97
  kind: "create",
98
98
  })];
99
99
  }
100
100
  else {
101
- if (descriptor.allChoices === true && excludedTemplates.has(descriptor.templateId)) {
101
+ if (descriptor.allChoices === true && excludedTemplates.has(formatTemplateId(descriptor.templateId))) {
102
102
  return [];
103
103
  }
104
104
  const choices = (descriptor.allChoices === true
105
- ? template.choices.filter((choice) => !excluded.has(`${descriptor.templateId}:${choice}`))
105
+ ? template.choices.filter((choice) => !excluded.has(`${formatTemplateId(descriptor.templateId)}:${choice}`))
106
106
  : descriptor.choices);
107
107
  const missingChoice = choices.find((choice) => !template.choices.includes(choice));
108
108
  if (missingChoice !== undefined) {
109
- throw new TestingConfigurationError(`Declarative target '${descriptor.templateId}:${missingChoice}' is absent from the DAML catalog.`);
109
+ throw new TestingConfigurationError(`Declarative target '${formatTemplateId(descriptor.templateId)}:${missingChoice}' is absent from the DAML catalog.`);
110
110
  }
111
111
  return choices
112
112
  .map((choice) => Object.freeze({
113
- key: `${descriptor.templateId}:${choice}`,
113
+ key: `${formatTemplateId(descriptor.templateId)}:${choice}`,
114
114
  templateId: descriptor.templateId,
115
115
  choice,
116
116
  actors: descriptor.actors,
@@ -119,3 +119,6 @@ export function resolveDeclarativeTargets(catalog, descriptors) {
119
119
  })
120
120
  .sort((left, right) => left.key.localeCompare(right.key));
121
121
  }
122
+ function formatTemplateId(templateId) {
123
+ return `${templateId.packageId}:${templateId.moduleName}:${templateId.entityName}`;
124
+ }
@@ -5,6 +5,7 @@ import { CommandStatus } from "../../../core/types/command-status.js";
5
5
  import { CommandTiming } from "../../../core/types/command-timing.js";
6
6
  import { CommandUpdateSummary } from "../../../core/types/command-update-summary.js";
7
7
  import { SdkCommand } from "../../../core/types/sdk-command.js";
8
+ import { DamlRecord } from "../../../core/types/daml-values.js";
8
9
  import { GetCommandStatusResponse } from "../../../core/types/responses/get-command-status-response.js";
9
10
  import { CommandState as GrpcCommandState, } from "../generated/canton/com/daml/ledger/api/v2/admin/command_inspection_service.js";
10
11
  import { mapGrpcCompletion } from "./command-completion-mapper.js";
@@ -118,21 +119,16 @@ function mapGrpcIdentifier(value) {
118
119
  if (value === undefined) {
119
120
  return undefined;
120
121
  }
121
- else if (value.packageId) {
122
- return `${value.packageId}:${value.moduleName}:${value.entityName}`;
123
- }
124
- else {
125
- return `${value.moduleName}:${value.entityName}`;
126
- }
122
+ return value;
127
123
  }
128
124
  function mapGrpcRecord(value) {
129
125
  if (value === undefined) {
130
126
  return undefined;
131
127
  }
132
- return Object.fromEntries(value.fields.map((field, index) => [
128
+ return new DamlRecord(Object.fromEntries(value.fields.map((field, index) => [
133
129
  field.label || index.toString(),
134
130
  mapGrpcValue(field.value),
135
- ]));
131
+ ])), mapGrpcIdentifier(value.recordId));
136
132
  }
137
133
  function mapGrpcValue(value) {
138
134
  switch (value?.sum.oneofKind) {
@@ -1,11 +1,12 @@
1
1
  import { CreateCommand } from "../../../core/types/commands/create-command.js";
2
+ import { DamlRecord } from "../../../core/types/daml-values.js";
2
3
  import { LedgerCommand } from "../../../core/types/commands/ledger-command.js";
3
4
  import { SubmitCommandRequest } from "../../../core/types/requests/submit-command-request.js";
4
5
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
5
6
  import { SubmitCommandTransactionResponse } from "../../../core/types/responses/submit-command-transaction-response.js";
6
7
  import { Command } from "../generated/canton/com/daml/ledger/api/v2/commands.js";
7
8
  import { SubmitAndWaitRequest, SubmitAndWaitResponse, SubmitAndWaitForTransactionRequest, SubmitAndWaitForTransactionResponse } from "../generated/canton/com/daml/ledger/api/v2/command_service.js";
8
- import { Identifier, Record as GrpcRecord, Value } from "../generated/canton/com/daml/ledger/api/v2/value.js";
9
+ import { Record as GrpcRecord, Value } from "../generated/canton/com/daml/ledger/api/v2/value.js";
9
10
  export declare function mapGrpcSubmitCommandRequest(request: SubmitCommandRequest): SubmitAndWaitRequest;
10
11
  export declare function mapGrpcSubmitCommandForTransactionRequest(request: SubmitCommandRequest): SubmitAndWaitForTransactionRequest;
11
12
  export declare function mapGrpcSubmitCommandTransaction(payload: SubmitAndWaitForTransactionResponse): SubmitCommandTransactionResponse;
@@ -16,6 +17,5 @@ export declare function mapGrpcSubmitCommand(payload: {
16
17
  } | SubmitAndWaitResponse): SubmitCommandResponse;
17
18
  export declare function mapGrpcLedgerCommand(command: LedgerCommand): Command;
18
19
  export declare function mapGrpcCreateCommand(command: CreateCommand): Command;
19
- export declare function mapRecord(payload: Record<string, unknown>): GrpcRecord;
20
+ export declare function mapRecord(payload: DamlRecord | Record<string, unknown>): GrpcRecord;
20
21
  export declare function mapValue(value: unknown): Value;
21
- export declare function parseTemplateIdentifier(templateId: string): Identifier;
@@ -30,8 +30,13 @@ export function mapGrpcSubmitCommandRequest(request) {
30
30
  },
31
31
  };
32
32
  }
33
- export function mapGrpcSubmitCommandForTransactionRequest(request) { return { commands: mapGrpcSubmitCommandRequest(request).commands }; }
34
- export function mapGrpcSubmitCommandTransaction(payload) { const transaction = payload.transaction; return new SubmitCommandTransactionResponse(transaction?.updateId ?? "", transaction?.events ?? [], transaction); }
33
+ export function mapGrpcSubmitCommandForTransactionRequest(request) {
34
+ return { commands: mapGrpcSubmitCommandRequest(request).commands };
35
+ }
36
+ export function mapGrpcSubmitCommandTransaction(payload) {
37
+ const transaction = payload.transaction;
38
+ return new SubmitCommandTransactionResponse(transaction?.updateId ?? "", transaction?.events ?? [], transaction);
39
+ }
35
40
  function mapGrpcDisclosedContract(value) {
36
41
  return { createdEventBlob: value.createdEventBlob, contractId: value.contractId ?? "", synchronizerId: value.synchronizerId ?? "", templateId: value.templateId === undefined ? undefined : { packageId: value.templateId.packageId, moduleName: value.templateId.moduleName, entityName: value.templateId.entityName } };
37
42
  }
@@ -52,10 +57,10 @@ export function mapGrpcLedgerCommand(command) {
52
57
  command: {
53
58
  oneofKind: "exercise",
54
59
  exercise: {
55
- templateId: parseTemplateIdentifier(command.templateId),
60
+ templateId: command.templateId,
56
61
  contractId: command.contractId,
57
62
  choice: command.choice,
58
- choiceArgument: mapValue(command.argument),
63
+ choiceArgument: mapValue(command.choiceArgument),
59
64
  },
60
65
  },
61
66
  };
@@ -65,10 +70,10 @@ export function mapGrpcLedgerCommand(command) {
65
70
  command: {
66
71
  oneofKind: "exerciseByKey",
67
72
  exerciseByKey: {
68
- templateId: parseTemplateIdentifier(command.templateId),
73
+ templateId: command.templateId,
69
74
  contractKey: mapValue(command.contractKey),
70
75
  choice: command.choice,
71
- choiceArgument: mapValue(command.argument),
76
+ choiceArgument: mapValue(command.choiceArgument),
72
77
  },
73
78
  },
74
79
  };
@@ -78,10 +83,10 @@ export function mapGrpcLedgerCommand(command) {
78
83
  command: {
79
84
  oneofKind: "createAndExercise",
80
85
  createAndExercise: {
81
- templateId: parseTemplateIdentifier(command.templateId),
82
- createArguments: mapRecord(command.payload),
86
+ templateId: command.templateId,
87
+ createArguments: mapRecord(command.createArguments),
83
88
  choice: command.choice,
84
- choiceArgument: mapValue(command.argument),
89
+ choiceArgument: mapValue(command.choiceArgument),
85
90
  },
86
91
  },
87
92
  };
@@ -93,15 +98,19 @@ export function mapGrpcCreateCommand(command) {
93
98
  command: {
94
99
  oneofKind: "create",
95
100
  create: {
96
- templateId: parseTemplateIdentifier(command.templateId),
97
- createArguments: mapRecord(command.payload),
101
+ templateId: command.templateId,
102
+ createArguments: mapRecord(command.createArguments),
98
103
  },
99
104
  },
100
105
  };
101
106
  }
102
107
  export function mapRecord(payload) {
108
+ const fields = payload instanceof DamlRecord ? payload.fields : payload;
103
109
  return {
104
- fields: Object.entries(payload).map(([label, value]) => ({
110
+ ...(payload instanceof DamlRecord && payload.recordId !== undefined
111
+ ? { recordId: payload.recordId }
112
+ : {}),
113
+ fields: Object.entries(fields).map(([label, value]) => ({
105
114
  label,
106
115
  value: mapValue(value),
107
116
  })),
@@ -109,23 +118,31 @@ export function mapRecord(payload) {
109
118
  }
110
119
  export function mapValue(value) {
111
120
  const identifier = (value) => ({ packageId: value.packageId, moduleName: value.moduleName, entityName: value.entityName });
112
- if (value instanceof DamlUnit)
121
+ if (value instanceof DamlUnit) {
113
122
  return { sum: { oneofKind: "unit", unit: {} } };
114
- if (value instanceof DamlDate)
123
+ }
124
+ else if (value instanceof DamlDate) {
115
125
  return { sum: { oneofKind: "date", date: value.daysSinceEpoch } };
116
- if (value instanceof DamlTimestamp)
126
+ }
127
+ else if (value instanceof DamlTimestamp) {
117
128
  return { sum: { oneofKind: "timestamp", timestamp: value.microsecondsSinceEpoch } };
118
- if (value instanceof DamlTextMap)
129
+ }
130
+ else if (value instanceof DamlTextMap) {
119
131
  return { sum: { oneofKind: "textMap", textMap: { entries: value.entries.map(([key, item]) => ({ key, value: mapValue(item) })) } } };
120
- if (value instanceof DamlGenMap)
132
+ }
133
+ else if (value instanceof DamlGenMap) {
121
134
  return { sum: { oneofKind: "genMap", genMap: { entries: value.entries.map(([key, item]) => ({ key: mapValue(key), value: mapValue(item) })) } } };
122
- if (value instanceof DamlVariant)
135
+ }
136
+ else if (value instanceof DamlVariant) {
123
137
  return { sum: { oneofKind: "variant", variant: { variantId: value.variantId && identifier(value.variantId), constructor: value.constructorName, value: mapValue(value.value) } } };
124
- if (value instanceof DamlEnum)
138
+ }
139
+ else if (value instanceof DamlEnum) {
125
140
  return { sum: { oneofKind: "enum", enum: { enumId: value.enumId && identifier(value.enumId), constructor: value.constructorName } } };
126
- if (value instanceof DamlRecord)
127
- return { sum: { oneofKind: "record", record: { recordId: value.recordId && identifier(value.recordId), fields: mapRecord(value.fields).fields } } };
128
- if (value === null || value === undefined) {
141
+ }
142
+ else if (value instanceof DamlRecord) {
143
+ return { sum: { oneofKind: "record", record: mapRecord(value) } };
144
+ }
145
+ else if (value === null || value === undefined) {
129
146
  return {
130
147
  sum: {
131
148
  oneofKind: "optional",
@@ -200,21 +217,3 @@ export function mapValue(value) {
200
217
  },
201
218
  };
202
219
  }
203
- export function parseTemplateIdentifier(templateId) {
204
- const parts = templateId.split(":");
205
- if (parts.length === 2) {
206
- return {
207
- packageId: "",
208
- moduleName: parts[0],
209
- entityName: parts[1],
210
- };
211
- }
212
- else if (parts.length === 3) {
213
- return {
214
- packageId: parts[0],
215
- moduleName: parts[1],
216
- entityName: parts[2],
217
- };
218
- }
219
- throw new ValidationError(`templateId must be '<module>:<entity>' or '<package>:<module>:<entity>', but was '${templateId}'.`);
220
- }
@@ -4,6 +4,7 @@ import { CreateAndExerciseCommand } from "../../../core/types/commands/create-an
4
4
  import { CreateCommand } from "../../../core/types/commands/create-command.js";
5
5
  import { DamlNumeric } from "../../../core/types/daml-numeric.js";
6
6
  import { DamlParty } from "../../../core/types/daml-party.js";
7
+ import { DamlRecord } from "../../../core/types/daml-values.js";
7
8
  import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
8
9
  import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
9
10
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
@@ -29,38 +30,38 @@ function mapJsonCommand(command) {
29
30
  if (command instanceof CreateCommand) {
30
31
  return {
31
32
  CreateCommand: {
32
- templateId: command.templateId,
33
- createArguments: mapJsonValue(command.payload),
33
+ templateId: formatTemplateId(command.templateId),
34
+ createArguments: mapJsonValue(command.createArguments.fields),
34
35
  },
35
36
  };
36
37
  }
37
38
  else if (command instanceof ExerciseCommand) {
38
39
  return {
39
40
  ExerciseCommand: {
40
- templateId: command.templateId,
41
+ templateId: formatTemplateId(command.templateId),
41
42
  contractId: command.contractId,
42
43
  choice: command.choice,
43
- choiceArgument: mapJsonValue(command.argument),
44
+ choiceArgument: mapJsonValue(command.choiceArgument),
44
45
  },
45
46
  };
46
47
  }
47
48
  else if (command instanceof ExerciseByKeyCommand) {
48
49
  return {
49
50
  ExerciseByKeyCommand: {
50
- templateId: command.templateId,
51
+ templateId: formatTemplateId(command.templateId),
51
52
  contractKey: mapJsonValue(command.contractKey),
52
53
  choice: command.choice,
53
- choiceArgument: mapJsonValue(command.argument),
54
+ choiceArgument: mapJsonValue(command.choiceArgument),
54
55
  },
55
56
  };
56
57
  }
57
58
  else if (command instanceof CreateAndExerciseCommand) {
58
59
  return {
59
60
  CreateAndExerciseCommand: {
60
- templateId: command.templateId,
61
- createArguments: mapJsonValue(command.payload),
61
+ templateId: formatTemplateId(command.templateId),
62
+ createArguments: mapJsonValue(command.createArguments.fields),
62
63
  choice: command.choice,
63
- choiceArgument: mapJsonValue(command.argument),
64
+ choiceArgument: mapJsonValue(command.choiceArgument),
64
65
  },
65
66
  };
66
67
  }
@@ -70,6 +71,9 @@ function mapJsonValue(value) {
70
71
  if (value instanceof DamlParty || value instanceof DamlNumeric) {
71
72
  return value.value;
72
73
  }
74
+ else if (value instanceof DamlRecord) {
75
+ return mapJsonValue(value.fields);
76
+ }
73
77
  else if (Array.isArray(value)) {
74
78
  return value.map(mapJsonValue);
75
79
  }
@@ -78,3 +82,8 @@ function mapJsonValue(value) {
78
82
  }
79
83
  return value;
80
84
  }
85
+ function formatTemplateId(templateId) {
86
+ return templateId.packageId.length === 0
87
+ ? `${templateId.moduleName}:${templateId.entityName}`
88
+ : `${templateId.packageId}:${templateId.moduleName}:${templateId.entityName}`;
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",