@distrohelena/canton-typescript-sdk 0.1.9 → 0.1.11

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.
@@ -0,0 +1,5 @@
1
+ /** Explicit DAML contract-id value, distinguished from ordinary text. */
2
+ export declare class DamlContractId {
3
+ readonly value: string;
4
+ constructor(value: string);
5
+ }
@@ -0,0 +1,11 @@
1
+ import { ValidationError } from "../errors/validation-error.js";
2
+ /** Explicit DAML contract-id value, distinguished from ordinary text. */
3
+ export class DamlContractId {
4
+ value;
5
+ constructor(value) {
6
+ if (value.length === 0) {
7
+ throw new ValidationError("DAML contract ids must not be empty");
8
+ }
9
+ this.value = value;
10
+ }
11
+ }
@@ -0,0 +1,35 @@
1
+ import { TemplateId } from "../../query/model-types.js";
2
+ export declare class DamlUnit {
3
+ }
4
+ export declare class DamlDate {
5
+ readonly daysSinceEpoch: number;
6
+ constructor(daysSinceEpoch: number);
7
+ }
8
+ export declare class DamlTimestamp {
9
+ readonly microsecondsSinceEpoch: string;
10
+ constructor(microsecondsSinceEpoch: string);
11
+ }
12
+ export declare class DamlTextMap {
13
+ readonly entries: readonly (readonly [string, unknown])[];
14
+ constructor(entries: readonly (readonly [string, unknown])[]);
15
+ }
16
+ export declare class DamlGenMap {
17
+ readonly entries: readonly (readonly [unknown, unknown])[];
18
+ constructor(entries: readonly (readonly [unknown, unknown])[]);
19
+ }
20
+ export declare class DamlVariant {
21
+ readonly constructorName: string;
22
+ readonly value: unknown;
23
+ readonly variantId?: TemplateId | undefined;
24
+ constructor(constructorName: string, value: unknown, variantId?: TemplateId | undefined);
25
+ }
26
+ export declare class DamlEnum {
27
+ readonly constructorName: string;
28
+ readonly enumId?: TemplateId | undefined;
29
+ constructor(constructorName: string, enumId?: TemplateId | undefined);
30
+ }
31
+ export declare class DamlRecord {
32
+ readonly fields: Readonly<Record<string, unknown>>;
33
+ readonly recordId?: TemplateId | undefined;
34
+ constructor(fields: Readonly<Record<string, unknown>>, recordId?: TemplateId | undefined);
35
+ }
@@ -0,0 +1,52 @@
1
+ export class DamlUnit {
2
+ }
3
+ export class DamlDate {
4
+ daysSinceEpoch;
5
+ constructor(daysSinceEpoch) {
6
+ this.daysSinceEpoch = daysSinceEpoch;
7
+ }
8
+ }
9
+ export class DamlTimestamp {
10
+ microsecondsSinceEpoch;
11
+ constructor(microsecondsSinceEpoch) {
12
+ this.microsecondsSinceEpoch = microsecondsSinceEpoch;
13
+ }
14
+ }
15
+ export class DamlTextMap {
16
+ entries;
17
+ constructor(entries) {
18
+ this.entries = entries;
19
+ }
20
+ }
21
+ export class DamlGenMap {
22
+ entries;
23
+ constructor(entries) {
24
+ this.entries = entries;
25
+ }
26
+ }
27
+ export class DamlVariant {
28
+ constructorName;
29
+ value;
30
+ variantId;
31
+ constructor(constructorName, value, variantId) {
32
+ this.constructorName = constructorName;
33
+ this.value = value;
34
+ this.variantId = variantId;
35
+ }
36
+ }
37
+ export class DamlEnum {
38
+ constructorName;
39
+ enumId;
40
+ constructor(constructorName, enumId) {
41
+ this.constructorName = constructorName;
42
+ this.enumId = enumId;
43
+ }
44
+ }
45
+ export class DamlRecord {
46
+ fields;
47
+ recordId;
48
+ constructor(fields, recordId) {
49
+ this.fields = fields;
50
+ this.recordId = recordId;
51
+ }
52
+ }
package/dist/index.d.ts CHANGED
@@ -208,6 +208,8 @@ export type { ExternalPartySigner, ExternalPartySigningRequest, ExternalPartySig
208
208
  export { AllocatePartyRequest } from "./core/types/requests/allocate-party-request.js";
209
209
  export { DisclosedContract } from "./core/types/disclosed-contract.js";
210
210
  export { PreparedCommandSubmission } from "./core/types/prepared-command-submission.js";
211
+ export { DamlContractId } from "./core/types/daml-contract-id.js";
212
+ export { DamlUnit, DamlDate, DamlTimestamp, DamlTextMap, DamlGenMap, DamlVariant, DamlEnum, DamlRecord } from "./core/types/daml-values.js";
211
213
  export { AddPartyAsyncArguments } from "./core/types/requests/add-party-async-request.js";
212
214
  export { AddPartyAsyncRequest } from "./core/types/requests/add-party-async-request.js";
213
215
  export { AssembleSignedTopologyTransactionsRequest } from "./core/types/requests/assemble-signed-topology-transactions-request.js";
package/dist/index.js CHANGED
@@ -195,6 +195,8 @@ export { CreateExternalPartyRequest, } from "./core/types/requests/create-extern
195
195
  export { AllocatePartyRequest } from "./core/types/requests/allocate-party-request.js";
196
196
  export { DisclosedContract } from "./core/types/disclosed-contract.js";
197
197
  export { PreparedCommandSubmission } from "./core/types/prepared-command-submission.js";
198
+ export { DamlContractId } from "./core/types/daml-contract-id.js";
199
+ export { DamlUnit, DamlDate, DamlTimestamp, DamlTextMap, DamlGenMap, DamlVariant, DamlEnum, DamlRecord } from "./core/types/daml-values.js";
198
200
  export { AddPartyAsyncArguments } from "./core/types/requests/add-party-async-request.js";
199
201
  export { AddPartyAsyncRequest } from "./core/types/requests/add-party-async-request.js";
200
202
  export { AssembleSignedTopologyTransactionsRequest } from "./core/types/requests/assemble-signed-topology-transactions-request.js";
@@ -44,7 +44,7 @@ export class GrpcContractQueryClient {
44
44
  args.where?.contractId?.in !== undefined ||
45
45
  args.where?.contractId?.is !== undefined ||
46
46
  args.where?.contractId?.isNot !== undefined ||
47
- (args.where?.templateId !== undefined && typeof args.where.templateId.equals !== "string")) {
47
+ args.where?.templateId !== undefined) {
48
48
  throw new QueryCapabilityError(QuerySource.grpc, "contracts.findMany");
49
49
  }
50
50
  const findArgs = args;
@@ -57,9 +57,6 @@ export class GrpcContractQueryClient {
57
57
  : row.contractId === args.where.contractId.equals);
58
58
  if (args.where?.payload !== undefined)
59
59
  rows = rows.filter((row) => matchesPayload(row.payload, args.where.payload));
60
- const legacyTemplate = args.where?.templateId;
61
- if (legacyTemplate?.equals !== undefined)
62
- rows = rows.filter((row) => `${row.templateId.packageId}:${row.templateId.moduleName}:${row.templateId.entityName}` === legacyTemplate.equals);
63
60
  return rows;
64
61
  }
65
62
  unsupported(operation) {
@@ -109,9 +109,7 @@ type PayloadValueFilter = {
109
109
  export type PayloadMatch = {
110
110
  readonly [field: string]: PayloadMatch | PayloadValueFilter;
111
111
  };
112
- export type ContractPayloadFilter = ({
113
- readonly path: string;
114
- } & PayloadValueFilter) | {
112
+ export type ContractPayloadFilter = {
115
113
  readonly match: PayloadMatch;
116
114
  };
117
115
  type ContractWhereFields = {
@@ -78,24 +78,13 @@ function compileWhere(where, addValue) {
78
78
  return;
79
79
  } for (const [name, child] of Object.entries(filter))
80
80
  compilePayload([...path, name], child); };
81
- if (payload.match !== undefined) {
82
- compilePayload([], payload.match);
83
- }
84
- else {
85
- const path = payload.path;
86
- if (typeof path !== "string" || path.split(".").some((x) => x.length === 0))
87
- throw new Error("payload path must contain non-empty segments");
88
- compilePayload(path.split("."), payload);
89
- }
81
+ if (payload.match === undefined)
82
+ throw new Error("payload requires match");
83
+ compilePayload([], payload.match);
90
84
  continue;
91
85
  }
92
86
  if (key === "templateId") {
93
87
  const fields = { packageId: "contract_row.creation_package_id", moduleName: "contract_tpe_row.module_name", entityName: "contract_tpe_row.entity_name" };
94
- const legacy = value;
95
- if (typeof legacy.equals === "string") {
96
- parts.push(`(contract_row.creation_package_id || ':' || contract_tpe_row.module_name || ':' || contract_tpe_row.entity_name) = ${addValue(legacy.equals)}`);
97
- continue;
98
- }
99
88
  for (const [name, filter] of Object.entries(value))
100
89
  for (const [op, operand] of Object.entries(filter)) {
101
90
  const sql = { equals: "=", lt: "<", lte: "<=", gt: ">", gte: ">=", like: "like", ilike: "ilike" }[op];
@@ -4,6 +4,8 @@ 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 { DamlContractId } from "../../../core/types/daml-contract-id.js";
8
+ import { DamlDate, DamlEnum, DamlGenMap, DamlRecord, DamlTextMap, DamlTimestamp, DamlUnit, DamlVariant } from "../../../core/types/daml-values.js";
7
9
  import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
8
10
  import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
9
11
  import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
@@ -103,6 +105,23 @@ export function mapRecord(payload) {
103
105
  };
104
106
  }
105
107
  export function mapValue(value) {
108
+ const identifier = (value) => ({ packageId: value.packageId, moduleName: value.moduleName, entityName: value.entityName });
109
+ if (value instanceof DamlUnit)
110
+ return { sum: { oneofKind: "unit", unit: {} } };
111
+ if (value instanceof DamlDate)
112
+ return { sum: { oneofKind: "date", date: value.daysSinceEpoch } };
113
+ if (value instanceof DamlTimestamp)
114
+ return { sum: { oneofKind: "timestamp", timestamp: value.microsecondsSinceEpoch } };
115
+ if (value instanceof DamlTextMap)
116
+ return { sum: { oneofKind: "textMap", textMap: { entries: value.entries.map(([key, item]) => ({ key, value: mapValue(item) })) } } };
117
+ if (value instanceof DamlGenMap)
118
+ return { sum: { oneofKind: "genMap", genMap: { entries: value.entries.map(([key, item]) => ({ key: mapValue(key), value: mapValue(item) })) } } };
119
+ if (value instanceof DamlVariant)
120
+ return { sum: { oneofKind: "variant", variant: { variantId: value.variantId && identifier(value.variantId), constructor: value.constructorName, value: mapValue(value.value) } } };
121
+ if (value instanceof DamlEnum)
122
+ 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 } } };
106
125
  if (value === null || value === undefined) {
107
126
  return {
108
127
  sum: {
@@ -119,6 +138,9 @@ export function mapValue(value) {
119
138
  },
120
139
  };
121
140
  }
141
+ else if (value instanceof DamlContractId) {
142
+ return { sum: { oneofKind: "contractId", contractId: value.value } };
143
+ }
122
144
  else if (value instanceof DamlNumeric) {
123
145
  return {
124
146
  sum: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distrohelena/canton-typescript-sdk",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",