@distrohelena/canton-typescript-sdk 0.1.11 → 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.
Files changed (36) hide show
  1. package/dist/core/transports/transport.interface.d.ts +2 -0
  2. package/dist/core/types/command-inspection-contract.d.ts +3 -2
  3. package/dist/core/types/commands/create-and-exercise-command.d.ts +8 -6
  4. package/dist/core/types/commands/create-and-exercise-command.js +9 -5
  5. package/dist/core/types/commands/create-command.d.ts +6 -4
  6. package/dist/core/types/commands/create-command.js +7 -3
  7. package/dist/core/types/commands/exercise-by-key-command.d.ts +5 -4
  8. package/dist/core/types/commands/exercise-by-key-command.js +3 -3
  9. package/dist/core/types/commands/exercise-command.d.ts +5 -4
  10. package/dist/core/types/commands/exercise-command.js +3 -3
  11. package/dist/core/types/responses/submit-command-transaction-response.d.ts +7 -0
  12. package/dist/core/types/responses/submit-command-transaction-response.js +11 -0
  13. package/dist/core/types/sdk-command.d.ts +6 -4
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +1 -0
  16. package/dist/services/command/command-service-client.d.ts +2 -0
  17. package/dist/services/command/command-service-client.js +1 -0
  18. package/dist/services/commands/command-payload-builder.js +11 -5
  19. package/dist/services/commands/command-submission-pipeline.d.ts +2 -0
  20. package/dist/services/commands/command-submission-pipeline.js +2 -0
  21. package/dist/testing/daml/daml-choice-action-arbitrary.d.ts +2 -1
  22. package/dist/testing/daml/daml-choice-action-arbitrary.js +4 -1
  23. package/dist/testing/daml/daml-create-action-arbitrary.d.ts +2 -1
  24. package/dist/testing/daml/daml-create-action-arbitrary.js +4 -1
  25. package/dist/testing/runtime/declarative-action-executor.js +3 -2
  26. package/dist/testing/targets/target.d.ts +12 -11
  27. package/dist/testing/targets/target.js +15 -12
  28. package/dist/transports/grpc/grpc-channel-factory.d.ts +2 -1
  29. package/dist/transports/grpc/grpc-channel-factory.js +4 -0
  30. package/dist/transports/grpc/grpc-transport.d.ts +1 -0
  31. package/dist/transports/grpc/grpc-transport.js +7 -1
  32. package/dist/transports/grpc/mappers/command-inspection-mapper.js +4 -8
  33. package/dist/transports/grpc/mappers/commands-mapper.d.ts +7 -4
  34. package/dist/transports/grpc/mappers/commands-mapper.js +40 -38
  35. package/dist/transports/json/mappers/commands-mapper.js +18 -9
  36. package/package.json +1 -1
@@ -188,6 +188,7 @@ import { TransactionObserver } from "../../services/events/transaction-observer.
188
188
  import { CommandSigners, ICommandSigner } from "../signing/command-signer.interface.js";
189
189
  import { SignCommandResult } from "../signing/sign-command-result.js";
190
190
  import { PreparedCommandSubmission } from "../types/prepared-command-submission.js";
191
+ import { SubmitCommandTransactionResponse } from "../types/responses/submit-command-transaction-response.js";
191
192
  import { RequestOptions } from "../types/request-options.js";
192
193
  import { SubmitCommandRequest } from "../types/requests/submit-command-request.js";
193
194
  export interface ITransport {
@@ -383,6 +384,7 @@ export interface ITransport {
383
384
  * Supported on JSON and gRPC. External signing is gRPC-only.
384
385
  */
385
386
  submitCommandAsync(request: SubmitCommandRequest, signer?: ICommandSigner | CommandSigners, options?: RequestOptions): Promise<SubmitCommandResponse>;
387
+ submitCommandForTransactionAsync?(request: SubmitCommandRequest, options?: RequestOptions): Promise<SubmitCommandTransactionResponse>;
386
388
  prepareCommandAsync?(request: SubmitCommandRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
387
389
  executePreparedCommandAndWaitAsync?(prepared: PreparedCommandSubmission, signatures: Readonly<Record<string, SignCommandResult>>, options?: RequestOptions): Promise<SubmitCommandResponse>;
388
390
  }
@@ -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
  }
@@ -0,0 +1,7 @@
1
+ /** Result of a gRPC command submission that waited for its transaction. */
2
+ export declare class SubmitCommandTransactionResponse {
3
+ readonly transactionId: string;
4
+ readonly events: readonly unknown[];
5
+ readonly transaction: unknown;
6
+ constructor(transactionId: string, events: readonly unknown[], transaction: unknown);
7
+ }
@@ -0,0 +1,11 @@
1
+ /** Result of a gRPC command submission that waited for its transaction. */
2
+ export class SubmitCommandTransactionResponse {
3
+ transactionId;
4
+ events;
5
+ transaction;
6
+ constructor(transactionId, events, transaction) {
7
+ this.transactionId = transactionId;
8
+ this.events = events;
9
+ this.transaction = transaction;
10
+ }
11
+ }
@@ -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";
@@ -210,6 +210,7 @@ export { DisclosedContract } from "./core/types/disclosed-contract.js";
210
210
  export { PreparedCommandSubmission } from "./core/types/prepared-command-submission.js";
211
211
  export { DamlContractId } from "./core/types/daml-contract-id.js";
212
212
  export { DamlUnit, DamlDate, DamlTimestamp, DamlTextMap, DamlGenMap, DamlVariant, DamlEnum, DamlRecord } from "./core/types/daml-values.js";
213
+ export { SubmitCommandTransactionResponse } from "./core/types/responses/submit-command-transaction-response.js";
213
214
  export { AddPartyAsyncArguments } from "./core/types/requests/add-party-async-request.js";
214
215
  export { AddPartyAsyncRequest } from "./core/types/requests/add-party-async-request.js";
215
216
  export { AssembleSignedTopologyTransactionsRequest } from "./core/types/requests/assemble-signed-topology-transactions-request.js";
package/dist/index.js CHANGED
@@ -197,6 +197,7 @@ export { DisclosedContract } from "./core/types/disclosed-contract.js";
197
197
  export { PreparedCommandSubmission } from "./core/types/prepared-command-submission.js";
198
198
  export { DamlContractId } from "./core/types/daml-contract-id.js";
199
199
  export { DamlUnit, DamlDate, DamlTimestamp, DamlTextMap, DamlGenMap, DamlVariant, DamlEnum, DamlRecord } from "./core/types/daml-values.js";
200
+ export { SubmitCommandTransactionResponse } from "./core/types/responses/submit-command-transaction-response.js";
200
201
  export { AddPartyAsyncArguments } from "./core/types/requests/add-party-async-request.js";
201
202
  export { AddPartyAsyncRequest } from "./core/types/requests/add-party-async-request.js";
202
203
  export { AssembleSignedTopologyTransactionsRequest } from "./core/types/requests/assemble-signed-topology-transactions-request.js";
@@ -3,11 +3,13 @@ import { RequestOptions } from "../../core/types/request-options.js";
3
3
  import { ITransport } from "../../core/transports/transport.interface.js";
4
4
  import { SubmitCommandRequest } from "../../core/types/requests/submit-command-request.js";
5
5
  import { SubmitCommandResponse } from "../../core/types/responses/submit-command-response.js";
6
+ import { SubmitCommandTransactionResponse } from "../../core/types/responses/submit-command-transaction-response.js";
6
7
  import { PreparedCommandSubmission } from "../../core/types/prepared-command-submission.js";
7
8
  import { SignCommandResult } from "../../core/signing/sign-command-result.js";
8
9
  export declare class CommandServiceClient {
9
10
  private readonly pipeline;
10
11
  constructor(transport: ITransport, signer?: ICommandSigner | CommandSigners);
12
+ submitAndWaitForTransactionAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<SubmitCommandTransactionResponse>;
11
13
  /** Submits a command and waits for the result. Supported on JSON and gRPC. */
12
14
  submitAndWaitAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<SubmitCommandResponse>;
13
15
  prepareAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
@@ -7,6 +7,7 @@ export class CommandServiceClient {
7
7
  signer,
8
8
  });
9
9
  }
10
+ submitAndWaitForTransactionAsync(request, options) { return this.pipeline.submitForTransactionAsync(request, options); }
10
11
  /** Submits a command and waits for the result. Supported on JSON and gRPC. */
11
12
  submitAndWaitAsync(request, options) {
12
13
  return this.pipeline.submitAsync(request, options);
@@ -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,6 +3,7 @@ import { ITransport } from "../../core/transports/transport.interface.js";
3
3
  import { RequestOptions } from "../../core/types/request-options.js";
4
4
  import { SubmitCommandRequest } from "../../core/types/requests/submit-command-request.js";
5
5
  import { SubmitCommandResponse } from "../../core/types/responses/submit-command-response.js";
6
+ import { SubmitCommandTransactionResponse } from "../../core/types/responses/submit-command-transaction-response.js";
6
7
  import { PreparedCommandSubmission } from "../../core/types/prepared-command-submission.js";
7
8
  import { SignCommandResult } from "../../core/signing/sign-command-result.js";
8
9
  export declare class CommandSubmissionPipeline {
@@ -12,6 +13,7 @@ export declare class CommandSubmissionPipeline {
12
13
  signer?: ICommandSigner | CommandSigners;
13
14
  });
14
15
  submitAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<SubmitCommandResponse>;
16
+ submitForTransactionAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<SubmitCommandTransactionResponse>;
15
17
  prepareAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
16
18
  executeAsync(prepared: PreparedCommandSubmission, signatures: Readonly<Record<string, SignCommandResult>>, options?: RequestOptions): Promise<SubmitCommandResponse>;
17
19
  }
@@ -12,6 +12,8 @@ export class CommandSubmissionPipeline {
12
12
  }
13
13
  return this.dependencies.transport.submitCommandAsync(request, this.dependencies.signer, options);
14
14
  }
15
+ submitForTransactionAsync(request, options) { if (!this.dependencies.transport.submitCommandForTransactionAsync)
16
+ throw new NotSupportedError("transaction-returning command submission is not supported by the selected transport"); return this.dependencies.transport.submitCommandForTransactionAsync(request, options); }
15
17
  prepareAsync(request, options) { if (!this.dependencies.transport.prepareCommandAsync)
16
18
  throw new NotSupportedError("interactive command preparation is not supported by the selected transport"); return this.dependencies.transport.prepareCommandAsync(request, options); }
17
19
  executeAsync(prepared, signatures, options) { if (!this.dependencies.transport.executePreparedCommandAndWaitAsync)
@@ -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
+ }
@@ -125,6 +125,7 @@ export interface GrpcOperations {
125
125
  prepareSubmissionAsync?(request: unknown, options?: RequestOptions): Promise<unknown>;
126
126
  executeSubmissionAndWaitAsync?(request: unknown, options?: RequestOptions): Promise<unknown>;
127
127
  submitCommandAsync(request: unknown, options?: RequestOptions): Promise<unknown>;
128
+ submitCommandForTransactionAsync?(request: unknown, options?: RequestOptions): Promise<unknown>;
128
129
  }
129
130
  export interface GrpcOperationDependencies {
130
131
  versionServiceClient?: Pick<IVersionServiceClient, "getLedgerApiVersion">;
@@ -154,6 +155,6 @@ export interface GrpcOperationDependencies {
154
155
  updateServiceClient?: Pick<IUpdateServiceClient, "getUpdates" | "getUpdateByOffset" | "getUpdateById" | "getUpdateByHash" | "getUpdatesPage">;
155
156
  commandCompletionServiceClient?: Pick<ICommandCompletionServiceClient, "getCompletions">;
156
157
  interactiveSubmissionServiceClient?: Pick<IInteractiveSubmissionServiceClient, "prepareSubmission" | "executeSubmissionAndWait">;
157
- commandServiceClient?: Pick<ICommandServiceClient, "submitAndWait">;
158
+ commandServiceClient?: Pick<ICommandServiceClient, "submitAndWait" | "submitAndWaitForTransaction">;
158
159
  }
159
160
  export declare function createGrpcOperations(options: CantonClientOptions, endpoint: string, grpcChannelSecurity: GrpcChannelSecurity, dependencies?: GrpcOperationDependencies): GrpcOperations;
@@ -463,6 +463,10 @@ export function createGrpcOperations(options, endpoint, grpcChannelSecurity, dep
463
463
  const callOptions = await buildCallOptionsForLedgerSurfaceAsync(options, requestOptions);
464
464
  return await unwrapUnaryResponse(commandServiceClient.submitAndWait(request, callOptions));
465
465
  },
466
+ async submitCommandForTransactionAsync(request, requestOptions) {
467
+ const callOptions = await buildCallOptionsForLedgerSurfaceAsync(options, requestOptions);
468
+ return await unwrapUnaryResponse(commandServiceClient.submitAndWaitForTransaction(request, callOptions));
469
+ },
466
470
  async prepareSubmissionAsync(request, requestOptions) {
467
471
  const callOptions = await buildCallOptionsForLedgerSurfaceAsync(options, requestOptions);
468
472
  return await unwrapUnaryResponse(interactiveSubmissionServiceClient.prepareSubmission(request, callOptions));
@@ -278,6 +278,7 @@ export declare class GrpcTransport implements ITransport {
278
278
  getUpdatesPageAsync(request: GetUpdatesPageRequest, options?: RequestOptions): Promise<GetUpdatesPageResponse>;
279
279
  getCompletionsAsync(request: GetCompletionsRequest, observer: CompletionObserver, options?: RequestOptions): Promise<void>;
280
280
  submitCommandAsync(request: SubmitCommandRequest, signer?: ICommandSigner | CommandSigners, options?: RequestOptions): Promise<SubmitCommandResponse>;
281
+ submitCommandForTransactionAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<import("../../core/types/responses/submit-command-transaction-response.js").SubmitCommandTransactionResponse>;
281
282
  prepareCommandAsync(request: SubmitCommandRequest, options?: RequestOptions): Promise<PreparedCommandSubmission>;
282
283
  executePreparedCommandAndWaitAsync(prepared: PreparedCommandSubmission, signatures: Readonly<Record<string, SignCommandResult>>, options?: RequestOptions): Promise<SubmitCommandResponse>;
283
284
  private throwIfDisposed;
@@ -11,7 +11,7 @@ import { NotSupportedError } from "../../core/errors/not-supported-error.js";
11
11
  import { TransportError } from "../../core/errors/transport-error.js";
12
12
  import { PackageFormat } from "../../core/types/package-format.js";
13
13
  import { createGrpcOperations, } from "./grpc-channel-factory.js";
14
- import { mapGrpcSubmitCommand, mapGrpcSubmitCommandRequest, } from "./mappers/commands-mapper.js";
14
+ import { mapGrpcSubmitCommand, mapGrpcSubmitCommandForTransactionRequest, mapGrpcSubmitCommandTransaction, mapGrpcSubmitCommandRequest, } from "./mappers/commands-mapper.js";
15
15
  import { mapGrpcExecuteSubmissionAndWaitRequest, mapGrpcInteractiveSubmitCommand, mapGrpcPrepareSubmissionRequest, } from "./mappers/interactive-command-mapper.js";
16
16
  import { mapGrpcGetContract, mapGrpcGetContractRequest, mapGrpcQueryContracts, mapGrpcQueryContractsRequest, } from "./mappers/contracts-mapper.js";
17
17
  import { mapGrpcCompletionStreamResponse, mapGrpcGetCompletionsRequest, } from "./mappers/command-completion-mapper.js";
@@ -617,6 +617,12 @@ export class GrpcTransport {
617
617
  }), options);
618
618
  return mapGrpcInteractiveSubmitCommand(executed);
619
619
  }
620
+ async submitCommandForTransactionAsync(request, options) {
621
+ this.throwIfDisposed();
622
+ if (!this.operations.submitCommandForTransactionAsync)
623
+ throw new NotSupportedError("transaction-returning command submission is not available on this transport");
624
+ return mapGrpcSubmitCommandTransaction(await this.operations.submitCommandForTransactionAsync(mapGrpcSubmitCommandForTransactionRequest(request), options));
625
+ }
620
626
  async prepareCommandAsync(request, options) {
621
627
  if (!this.operations.prepareSubmissionAsync)
622
628
  throw new NotSupportedError("interactive gRPC command signing is not available on this transport");
@@ -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,15 @@
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";
6
+ import { SubmitCommandTransactionResponse } from "../../../core/types/responses/submit-command-transaction-response.js";
5
7
  import { Command } from "../generated/canton/com/daml/ledger/api/v2/commands.js";
6
- import { SubmitAndWaitRequest, SubmitAndWaitResponse } from "../generated/canton/com/daml/ledger/api/v2/command_service.js";
7
- import { Identifier, Record as GrpcRecord, Value } from "../generated/canton/com/daml/ledger/api/v2/value.js";
8
+ import { SubmitAndWaitRequest, SubmitAndWaitResponse, SubmitAndWaitForTransactionRequest, SubmitAndWaitForTransactionResponse } from "../generated/canton/com/daml/ledger/api/v2/command_service.js";
9
+ import { Record as GrpcRecord, Value } from "../generated/canton/com/daml/ledger/api/v2/value.js";
8
10
  export declare function mapGrpcSubmitCommandRequest(request: SubmitCommandRequest): SubmitAndWaitRequest;
11
+ export declare function mapGrpcSubmitCommandForTransactionRequest(request: SubmitCommandRequest): SubmitAndWaitForTransactionRequest;
12
+ export declare function mapGrpcSubmitCommandTransaction(payload: SubmitAndWaitForTransactionResponse): SubmitCommandTransactionResponse;
9
13
  export declare function mapGrpcSubmitCommand(payload: {
10
14
  commandId?: string;
11
15
  transactionId?: string;
@@ -13,6 +17,5 @@ export declare function mapGrpcSubmitCommand(payload: {
13
17
  } | SubmitAndWaitResponse): SubmitCommandResponse;
14
18
  export declare function mapGrpcLedgerCommand(command: LedgerCommand): Command;
15
19
  export declare function mapGrpcCreateCommand(command: CreateCommand): Command;
16
- export declare function mapRecord(payload: Record<string, unknown>): GrpcRecord;
20
+ export declare function mapRecord(payload: DamlRecord | Record<string, unknown>): GrpcRecord;
17
21
  export declare function mapValue(value: unknown): Value;
18
- export declare function parseTemplateIdentifier(templateId: string): Identifier;
@@ -9,6 +9,7 @@ import { DamlDate, DamlEnum, DamlGenMap, DamlRecord, DamlTextMap, DamlTimestamp,
9
9
  import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
10
10
  import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
11
11
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
12
+ import { SubmitCommandTransactionResponse } from "../../../core/types/responses/submit-command-transaction-response.js";
12
13
  export function mapGrpcSubmitCommandRequest(request) {
13
14
  return {
14
15
  commands: {
@@ -29,6 +30,13 @@ export function mapGrpcSubmitCommandRequest(request) {
29
30
  },
30
31
  };
31
32
  }
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
+ }
32
40
  function mapGrpcDisclosedContract(value) {
33
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 } };
34
42
  }
@@ -49,10 +57,10 @@ export function mapGrpcLedgerCommand(command) {
49
57
  command: {
50
58
  oneofKind: "exercise",
51
59
  exercise: {
52
- templateId: parseTemplateIdentifier(command.templateId),
60
+ templateId: command.templateId,
53
61
  contractId: command.contractId,
54
62
  choice: command.choice,
55
- choiceArgument: mapValue(command.argument),
63
+ choiceArgument: mapValue(command.choiceArgument),
56
64
  },
57
65
  },
58
66
  };
@@ -62,10 +70,10 @@ export function mapGrpcLedgerCommand(command) {
62
70
  command: {
63
71
  oneofKind: "exerciseByKey",
64
72
  exerciseByKey: {
65
- templateId: parseTemplateIdentifier(command.templateId),
73
+ templateId: command.templateId,
66
74
  contractKey: mapValue(command.contractKey),
67
75
  choice: command.choice,
68
- choiceArgument: mapValue(command.argument),
76
+ choiceArgument: mapValue(command.choiceArgument),
69
77
  },
70
78
  },
71
79
  };
@@ -75,10 +83,10 @@ export function mapGrpcLedgerCommand(command) {
75
83
  command: {
76
84
  oneofKind: "createAndExercise",
77
85
  createAndExercise: {
78
- templateId: parseTemplateIdentifier(command.templateId),
79
- createArguments: mapRecord(command.payload),
86
+ templateId: command.templateId,
87
+ createArguments: mapRecord(command.createArguments),
80
88
  choice: command.choice,
81
- choiceArgument: mapValue(command.argument),
89
+ choiceArgument: mapValue(command.choiceArgument),
82
90
  },
83
91
  },
84
92
  };
@@ -90,15 +98,19 @@ export function mapGrpcCreateCommand(command) {
90
98
  command: {
91
99
  oneofKind: "create",
92
100
  create: {
93
- templateId: parseTemplateIdentifier(command.templateId),
94
- createArguments: mapRecord(command.payload),
101
+ templateId: command.templateId,
102
+ createArguments: mapRecord(command.createArguments),
95
103
  },
96
104
  },
97
105
  };
98
106
  }
99
107
  export function mapRecord(payload) {
108
+ const fields = payload instanceof DamlRecord ? payload.fields : payload;
100
109
  return {
101
- 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]) => ({
102
114
  label,
103
115
  value: mapValue(value),
104
116
  })),
@@ -106,23 +118,31 @@ export function mapRecord(payload) {
106
118
  }
107
119
  export function mapValue(value) {
108
120
  const identifier = (value) => ({ packageId: value.packageId, moduleName: value.moduleName, entityName: value.entityName });
109
- if (value instanceof DamlUnit)
121
+ if (value instanceof DamlUnit) {
110
122
  return { sum: { oneofKind: "unit", unit: {} } };
111
- if (value instanceof DamlDate)
123
+ }
124
+ else if (value instanceof DamlDate) {
112
125
  return { sum: { oneofKind: "date", date: value.daysSinceEpoch } };
113
- if (value instanceof DamlTimestamp)
126
+ }
127
+ else if (value instanceof DamlTimestamp) {
114
128
  return { sum: { oneofKind: "timestamp", timestamp: value.microsecondsSinceEpoch } };
115
- if (value instanceof DamlTextMap)
129
+ }
130
+ else if (value instanceof DamlTextMap) {
116
131
  return { sum: { oneofKind: "textMap", textMap: { entries: value.entries.map(([key, item]) => ({ key, value: mapValue(item) })) } } };
117
- if (value instanceof DamlGenMap)
132
+ }
133
+ else if (value instanceof DamlGenMap) {
118
134
  return { sum: { oneofKind: "genMap", genMap: { entries: value.entries.map(([key, item]) => ({ key: mapValue(key), value: mapValue(item) })) } } };
119
- if (value instanceof DamlVariant)
135
+ }
136
+ else if (value instanceof DamlVariant) {
120
137
  return { sum: { oneofKind: "variant", variant: { variantId: value.variantId && identifier(value.variantId), constructor: value.constructorName, value: mapValue(value.value) } } };
121
- if (value instanceof DamlEnum)
138
+ }
139
+ else if (value instanceof DamlEnum) {
122
140
  return { sum: { oneofKind: "enum", enum: { enumId: value.enumId && identifier(value.enumId), constructor: value.constructorName } } };
123
- if (value instanceof DamlRecord)
124
- return { sum: { oneofKind: "record", record: { recordId: value.recordId && identifier(value.recordId), fields: mapRecord(value.fields).fields } } };
125
- 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) {
126
146
  return {
127
147
  sum: {
128
148
  oneofKind: "optional",
@@ -197,21 +217,3 @@ export function mapValue(value) {
197
217
  },
198
218
  };
199
219
  }
200
- export function parseTemplateIdentifier(templateId) {
201
- const parts = templateId.split(":");
202
- if (parts.length === 2) {
203
- return {
204
- packageId: "",
205
- moduleName: parts[0],
206
- entityName: parts[1],
207
- };
208
- }
209
- else if (parts.length === 3) {
210
- return {
211
- packageId: parts[0],
212
- moduleName: parts[1],
213
- entityName: parts[2],
214
- };
215
- }
216
- throw new ValidationError(`templateId must be '<module>:<entity>' or '<package>:<module>:<entity>', but was '${templateId}'.`);
217
- }
@@ -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.11",
3
+ "version": "0.1.13",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",