@distrohelena/canton-typescript-sdk 0.1.24 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +10 -5
  2. package/dist/daml-interface/analysis/analyzed-choice.d.ts +5 -5
  3. package/dist/daml-interface/analysis/analyzed-daml-type-definition.d.ts +6 -0
  4. package/dist/daml-interface/analysis/analyzed-daml-type-definition.js +1 -0
  5. package/dist/daml-interface/analysis/analyzed-daml-type.d.ts +54 -0
  6. package/dist/daml-interface/analysis/analyzed-daml-type.js +1 -0
  7. package/dist/daml-interface/analysis/analyzed-template.d.ts +3 -3
  8. package/dist/daml-interface/analysis/daml-interface-analyzer.d.ts +3 -1
  9. package/dist/daml-interface/analysis/daml-interface-analyzer.js +183 -19
  10. package/dist/daml-interface/emission/named-type-emitter.d.ts +41 -0
  11. package/dist/daml-interface/emission/named-type-emitter.js +441 -0
  12. package/dist/daml-interface/emission/project-emitter.d.ts +5 -1
  13. package/dist/daml-interface/emission/project-emitter.js +20 -3
  14. package/dist/daml-interface/emission/registry-emitter.d.ts +1 -0
  15. package/dist/daml-interface/emission/registry-emitter.js +15 -8
  16. package/dist/daml-interface/emission/support-file-emitter.d.ts +16 -1
  17. package/dist/daml-interface/emission/support-file-emitter.js +206 -6
  18. package/dist/daml-interface/emission/template-binding-emitter.d.ts +25 -1
  19. package/dist/daml-interface/emission/template-binding-emitter.js +373 -72
  20. package/dist/daml-interface/emission/type-script-name-resolver.d.ts +50 -3
  21. package/dist/daml-interface/emission/type-script-name-resolver.js +369 -11
  22. package/dist/daml-interface/emission-model/generated-choice-binding.d.ts +7 -0
  23. package/dist/daml-interface/emission-model/generated-choice-binding.js +6 -0
  24. package/dist/daml-interface/emission-model/generated-daml-interface-project.d.ts +3 -0
  25. package/dist/daml-interface/emission-model/generated-daml-interface-project.js +2 -0
  26. package/dist/daml-interface/emission-model/generated-named-type-file.d.ts +23 -0
  27. package/dist/daml-interface/emission-model/generated-named-type-file.js +23 -0
  28. package/dist/daml-interface/emission-model/generated-template-binding.d.ts +9 -0
  29. package/dist/daml-interface/emission-model/generated-template-binding.js +8 -0
  30. package/dist/daml-interface/index.d.ts +12 -0
  31. package/dist/daml-interface/index.js +9 -0
  32. package/dist/daml-interface/runtime/daml-event-source-normalizer.d.ts +52 -0
  33. package/dist/daml-interface/runtime/daml-event-source-normalizer.js +364 -0
  34. package/dist/daml-interface/runtime/daml-materialization-error.d.ts +5 -0
  35. package/dist/daml-interface/runtime/daml-materialization-error.js +9 -0
  36. package/dist/daml-interface/runtime/daml-template.d.ts +6 -0
  37. package/dist/daml-interface/runtime/daml-template.js +10 -0
  38. package/dist/daml-interface/runtime/daml-type-descriptor.d.ts +71 -0
  39. package/dist/daml-interface/runtime/daml-type-descriptor.js +1 -0
  40. package/dist/daml-interface/runtime/daml-value-converter.d.ts +7 -0
  41. package/dist/daml-interface/runtime/daml-value-converter.js +370 -0
  42. package/dist/daml-interface/runtime/daml-value-materializer.d.ts +3 -0
  43. package/dist/daml-interface/runtime/daml-value-materializer.js +23 -0
  44. package/dist/daml-interface/writing/daml-interface-writer.js +1 -0
  45. package/dist/daml-lf/daml-lf-compilation.d.ts +1 -0
  46. package/dist/daml-lf/daml-lf-compilation.js +24 -3
  47. package/dist/daml-lf/model/daml-lf-builtin-type.d.ts +9 -0
  48. package/dist/daml-lf/model/daml-lf-builtin-type.js +9 -0
  49. package/dist/daml-lf/model/daml-lf-data-type.d.ts +18 -1
  50. package/dist/daml-lf/model/daml-lf-data-type.js +8 -1
  51. package/dist/daml-lf/model/daml-lf-type.d.ts +2 -0
  52. package/dist/daml-lf/model/daml-lf-type.js +2 -0
  53. package/dist/daml-lf/model/lf-2-model-mapper.d.ts +1 -0
  54. package/dist/daml-lf/model/lf-2-model-mapper.js +81 -25
  55. package/dist/daml-lf/semantics/daml-lf-semantic-model.d.ts +3 -0
  56. package/dist/daml-lf/semantics/daml-lf-semantic-model.js +5 -1
  57. package/dist/query/pqs/pqs-query-client.js +15 -0
  58. package/dist/query/pqs/pqs-sql-compiler.js +35 -7
  59. package/package.json +1 -1
@@ -0,0 +1,52 @@
1
+ import { GetContractResponse } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/contract_service.js";
2
+ import { CreatedEvent, Event, ExercisedEvent } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/event.js";
3
+ import { ActiveContract } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/state_service.js";
4
+ import type { ContractResult, ExerciseResult } from "../../query/model-types.js";
5
+ import type { DamlTypeIdentity, DamlValueSource } from "./daml-type-descriptor.js";
6
+ export type DamlJsonEventRecord = Readonly<Record<string, unknown>>;
7
+ export type DamlCreatedEventSource = CreatedEvent | GetContractResponse | ActiveContract | ContractResult | Event | DamlJsonEventRecord;
8
+ export type DamlExercisedEventSource = ExercisedEvent | ExerciseResult | Event | DamlJsonEventRecord;
9
+ export type DamlCreatedEventMetadata = {
10
+ readonly templateId: DamlTypeIdentity;
11
+ readonly offset?: string;
12
+ readonly nodeId?: number;
13
+ readonly witnessParties?: readonly string[];
14
+ readonly signatories?: readonly string[];
15
+ readonly observers?: readonly string[];
16
+ /** Canonical UTC ISO-8601 timestamp. */
17
+ readonly createdAt?: string;
18
+ };
19
+ export type DamlExercisedEventMetadata = {
20
+ readonly templateId: DamlTypeIdentity;
21
+ readonly offset?: string;
22
+ readonly nodeId?: number;
23
+ readonly actingParties?: readonly string[];
24
+ readonly witnessParties?: readonly string[];
25
+ readonly lastDescendantNodeId?: number;
26
+ };
27
+ export type DamlNormalizedCreatedEvent = {
28
+ readonly kind: "created";
29
+ readonly contractId: string;
30
+ readonly payload: DamlValueSource;
31
+ readonly metadata: DamlCreatedEventMetadata;
32
+ };
33
+ export type DamlNormalizedExercisedEvent = {
34
+ readonly kind: "exercised";
35
+ readonly contractId: string;
36
+ readonly choice: string;
37
+ readonly argument: DamlValueSource;
38
+ readonly result: DamlValueSource;
39
+ readonly consuming: boolean;
40
+ readonly metadata: DamlExercisedEventMetadata;
41
+ };
42
+ /**
43
+ * Recognizes a Ledger API create event, a contract response/wrapper, or a
44
+ * PQS/JSON contract record and produces one immutable runtime shape.
45
+ */
46
+ export declare function normalizeDamlCreatedEventSource(source: DamlCreatedEventSource): DamlNormalizedCreatedEvent;
47
+ /**
48
+ * Recognizes a Ledger API exercise event or a PQS/JSON exercise record and
49
+ * produces one immutable runtime shape. Choice information may be supplied by
50
+ * PQS's exercise-type relation and identity by its contract relation.
51
+ */
52
+ export declare function normalizeDamlExercisedEventSource(source: DamlExercisedEventSource): DamlNormalizedExercisedEvent;
@@ -0,0 +1,364 @@
1
+ import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
2
+ import { GetContractResponse } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/contract_service.js";
3
+ import { CreatedEvent, ExercisedEvent } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/event.js";
4
+ import { ActiveContract } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/state_service.js";
5
+ import { DamlMaterializationError } from "./daml-materialization-error.js";
6
+ const DAML_MIN_TIMESTAMP_SECONDS = -62135596800n;
7
+ const DAML_MAX_TIMESTAMP_SECONDS = 253402300799n;
8
+ /**
9
+ * Recognizes a Ledger API create event, a contract response/wrapper, or a
10
+ * PQS/JSON contract record and produces one immutable runtime shape.
11
+ */
12
+ export function normalizeDamlCreatedEventSource(source) {
13
+ const recognized = findNestedEvent(source, "created");
14
+ const { event } = recognized;
15
+ const contractId = requiredString(event, ["contractId", "contract_id"], "contract ID", "created event source");
16
+ const templateId = requiredIdentity(event, source, "created event source");
17
+ const payload = requiredProperty(event, ["createArguments", "create_arguments", "payload"], "created payload", "created event source");
18
+ const metadata = freezeCreatedMetadata(event, templateId);
19
+ return Object.freeze({
20
+ kind: "created",
21
+ contractId,
22
+ payload: freezeValueSource(payload, recognized.encoding === "protobuf" ? "protobuf-record" : "json"),
23
+ metadata,
24
+ });
25
+ }
26
+ /**
27
+ * Recognizes a Ledger API exercise event or a PQS/JSON exercise record and
28
+ * produces one immutable runtime shape. Choice information may be supplied by
29
+ * PQS's exercise-type relation and identity by its contract relation.
30
+ */
31
+ export function normalizeDamlExercisedEventSource(source) {
32
+ const recognized = findNestedEvent(source, "exercised");
33
+ const { event } = recognized;
34
+ const contractId = requiredString(event, ["contractId", "contract_id"], "contract ID", "exercised event source");
35
+ const templateId = requiredIdentity(event, source, "exercised event source");
36
+ const choice = requiredStringFrom(event, source, ["choice"], "choice", "exercised event source");
37
+ const consuming = requiredBooleanFrom(event, source, ["consuming"], "consuming", "exercised event source");
38
+ const argument = requiredProperty(event, ["choiceArgument", "choice_argument", "argument"], "exercise argument", "exercised event source");
39
+ const result = requiredProperty(event, ["exerciseResult", "exercise_result", "result"], "exercise result", "exercised event source");
40
+ const metadata = freezeExercisedMetadata(event, source, templateId);
41
+ return Object.freeze({
42
+ kind: "exercised",
43
+ contractId,
44
+ choice,
45
+ argument: freezeValueSource(argument, recognized.encoding),
46
+ result: freezeValueSource(result, recognized.encoding),
47
+ consuming,
48
+ metadata,
49
+ });
50
+ }
51
+ function findNestedEvent(source, kind) {
52
+ const root = objectOrThrow(source, `${kind} event source`, "source must be an object");
53
+ const candidates = [];
54
+ const aliases = kind === "created" ? ["createdEvent", "created_event"] : ["exercisedEvent", "exercised_event"];
55
+ if (looksLikeEvent(root, kind)) {
56
+ candidates.push({ event: root, encoding: protobufEncoding(root, kind) });
57
+ }
58
+ for (const alias of aliases) {
59
+ if (hasValue(root, alias)) {
60
+ candidates.push({ event: objectOrThrow(root[alias], `${kind} event source`, "event must be an object"), encoding: protobufEncoding(root, kind) });
61
+ }
62
+ }
63
+ const nested = asObject(root.event);
64
+ if (nested !== undefined) {
65
+ const nestedAliases = kind === "created" ? ["created", "createdEvent", "created_event"] : ["exercised", "exercisedEvent", "exercised_event"];
66
+ for (const alias of nestedAliases) {
67
+ if (hasValue(nested, alias)) {
68
+ candidates.push({ event: objectOrThrow(nested[alias], `${kind} event source`, "event must be an object"), encoding: protobufEncoding(nested[alias], kind) });
69
+ }
70
+ }
71
+ }
72
+ if (candidates.length === 0) {
73
+ throw sourceError(`${kind} event source`, "no event or payload was found");
74
+ }
75
+ else if (candidates.length !== 1) {
76
+ throw sourceError(`${kind} event source`, "ambiguous nested event");
77
+ }
78
+ return candidates[0];
79
+ }
80
+ function protobufEncoding(value, kind) {
81
+ if (isGeneratedMessage(value, kind === "created" ? CreatedEvent : ExercisedEvent)) {
82
+ return "protobuf";
83
+ }
84
+ else if (kind === "created" && (isGeneratedMessage(value, GetContractResponse) || isGeneratedMessage(value, ActiveContract))) {
85
+ return "protobuf";
86
+ }
87
+ return "json";
88
+ }
89
+ function isGeneratedMessage(value, type) {
90
+ return value !== null
91
+ && typeof value === "object"
92
+ && value[MESSAGE_TYPE] === type;
93
+ }
94
+ function looksLikeEvent(value, kind) {
95
+ const fields = kind === "created"
96
+ ? ["contractId", "contract_id", "templateId", "template_id", "createArguments", "create_arguments", "payload"]
97
+ : ["contractId", "contract_id", "templateId", "template_id", "choiceArgument", "choice_argument", "argument", "exerciseResult", "exercise_result", "result"];
98
+ return fields.some((field) => Object.prototype.hasOwnProperty.call(value, field));
99
+ }
100
+ function requiredIdentity(event, source, path) {
101
+ const direct = readProperty(event, ["templateId", "template_id"]);
102
+ if (direct.found) {
103
+ return identityFrom(direct.value, path);
104
+ }
105
+ const root = asObject(source);
106
+ const contract = asObject(readProperty(event, ["contract"]).value) ?? asObject(root?.contract);
107
+ const contractIdentity = contract === undefined ? { found: false } : readProperty(contract, ["templateId", "template_id"]);
108
+ if (contractIdentity.found) {
109
+ return identityFrom(contractIdentity.value, path);
110
+ }
111
+ const type = asObject(readProperty(event, ["exerciseType", "exercise_type", "contractType", "contract_type"]).value)
112
+ ?? asObject(root?.exerciseType)
113
+ ?? asObject(root?.exercise_type)
114
+ ?? asObject(root?.contractType)
115
+ ?? asObject(root?.contract_type);
116
+ const packageRecord = asObject(readProperty(event, ["package"]).value) ?? asObject(root?.package);
117
+ if (type !== undefined) {
118
+ return identityFrom({
119
+ packageId: readProperty(type, ["packageId", "package_id"]).value ?? readProperty(packageRecord ?? {}, ["id", "packageId", "package_id"]).value,
120
+ moduleName: readProperty(type, ["moduleName", "module_name"]).value,
121
+ entityName: readProperty(type, ["entityName", "entity_name"]).value,
122
+ }, path);
123
+ }
124
+ throw sourceError(path, "template identity is absent");
125
+ }
126
+ function identityFrom(value, path) {
127
+ const identifier = asObject(value);
128
+ if (identifier === undefined) {
129
+ throw sourceError(path, "template identity is absent");
130
+ }
131
+ const packageId = stringValue(readProperty(identifier, ["packageId", "package_id"]).value);
132
+ const moduleName = stringValue(readProperty(identifier, ["moduleName", "module_name"]).value);
133
+ const entityName = stringValue(readProperty(identifier, ["entityName", "entity_name"]).value);
134
+ if (packageId === undefined || moduleName === undefined || entityName === undefined) {
135
+ throw sourceError(path, "template identity is incomplete");
136
+ }
137
+ return Object.freeze({ packageId, moduleName, entityName });
138
+ }
139
+ function freezeCreatedMetadata(event, templateId) {
140
+ return Object.freeze(removeUndefined({
141
+ templateId,
142
+ offset: optionalString(event, ["offset", "createdEventOffset", "created_event_offset"], "offset", "created event source"),
143
+ nodeId: optionalNodeId(event, ["nodeId", "node_id"], "node ID", "created event source"),
144
+ witnessParties: optionalStringArray(event, ["witnessParties", "witness_parties", "witnesses"], "witness parties", "created event source"),
145
+ signatories: optionalStringArray(event, ["signatories"], "signatories", "created event source"),
146
+ observers: optionalStringArray(event, ["observers"], "observers", "created event source"),
147
+ createdAt: optionalCreatedAt(event, ["createdAt", "created_at"], "created event source"),
148
+ }));
149
+ }
150
+ function freezeExercisedMetadata(event, source, templateId) {
151
+ const root = asObject(source);
152
+ const transaction = asObject(readProperty(event, ["transaction"]).value) ?? asObject(root?.transaction);
153
+ return Object.freeze(removeUndefined({
154
+ templateId,
155
+ offset: optionalString(event, ["offset"], "offset", "exercised event source")
156
+ ?? optionalString(transaction ?? {}, ["offset"], "offset", "exercised event source"),
157
+ nodeId: optionalNodeId(event, ["nodeId", "node_id"], "node ID", "exercised event source"),
158
+ actingParties: optionalStringArray(event, ["actingParties", "acting_parties", "controllers"], "acting parties", "exercised event source"),
159
+ witnessParties: optionalStringArray(event, ["witnessParties", "witness_parties", "witnesses"], "witness parties", "exercised event source"),
160
+ lastDescendantNodeId: optionalNodeId(event, ["lastDescendantNodeId", "last_descendant_node_id"], "last descendant node ID", "exercised event source"),
161
+ }));
162
+ }
163
+ function requiredStringFrom(event, source, names, label, path) {
164
+ const direct = readProperty(event, names);
165
+ if (direct.found) {
166
+ return requiredStringValue(direct.value, label, path);
167
+ }
168
+ const root = asObject(source);
169
+ const type = asObject(readProperty(event, ["exerciseType", "exercise_type"]).value)
170
+ ?? asObject(root?.exerciseType)
171
+ ?? asObject(root?.exercise_type);
172
+ const nested = type === undefined ? { found: false } : readProperty(type, names);
173
+ return requiredStringValue(nested.value, label, path);
174
+ }
175
+ function requiredBooleanFrom(event, source, names, label, path) {
176
+ const direct = readProperty(event, names);
177
+ if (direct.found) {
178
+ return requiredBooleanValue(direct.value, label, path);
179
+ }
180
+ const root = asObject(source);
181
+ const type = asObject(readProperty(event, ["exerciseType", "exercise_type"]).value)
182
+ ?? asObject(root?.exerciseType)
183
+ ?? asObject(root?.exercise_type);
184
+ const nested = type === undefined ? { found: false } : readProperty(type, names);
185
+ return requiredBooleanValue(nested.value, label, path);
186
+ }
187
+ function requiredString(event, names, label, path) {
188
+ return requiredStringValue(readProperty(event, names).value, label, path);
189
+ }
190
+ function requiredStringValue(value, label, path) {
191
+ const string = stringValue(value);
192
+ if (string === undefined) {
193
+ throw sourceError(path, `${label} is absent`);
194
+ }
195
+ return string;
196
+ }
197
+ function requiredBooleanValue(value, label, path) {
198
+ if (typeof value !== "boolean") {
199
+ throw sourceError(path, `${label} is absent`);
200
+ }
201
+ return value;
202
+ }
203
+ function requiredProperty(event, names, label, path) {
204
+ const property = readProperty(event, names);
205
+ if (!property.found) {
206
+ throw sourceError(path, `${label} is absent`);
207
+ }
208
+ return property.value;
209
+ }
210
+ function freezeValueSource(value, encoding) {
211
+ if (encoding === "protobuf") {
212
+ return Object.freeze({ kind: "protobuf", value: cloneAndFreeze(value) });
213
+ }
214
+ else if (encoding === "protobuf-record") {
215
+ return Object.freeze({
216
+ kind: "protobuf",
217
+ value: cloneAndFreeze({ sum: { oneofKind: "record", record: value } }),
218
+ });
219
+ }
220
+ return Object.freeze({ kind: "json", value: cloneAndFreeze(value) });
221
+ }
222
+ function optionalString(event, names, label, path) {
223
+ const property = readProperty(event, names);
224
+ if (!property.found) {
225
+ return undefined;
226
+ }
227
+ const value = stringValue(property.value);
228
+ if (value === undefined) {
229
+ throw sourceError(path, `${label} must be a non-empty string`);
230
+ }
231
+ return value;
232
+ }
233
+ function optionalNodeId(event, names, label, path) {
234
+ const property = readProperty(event, names);
235
+ if (!property.found) {
236
+ return undefined;
237
+ }
238
+ const value = property.value;
239
+ const number = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value) ? Number(value) : undefined;
240
+ if (number === undefined || !Number.isSafeInteger(number) || number < 0) {
241
+ throw sourceError(path, `${label} must be a non-negative safe integer`);
242
+ }
243
+ return number;
244
+ }
245
+ function optionalStringArray(event, names, label, path) {
246
+ const property = readProperty(event, names);
247
+ if (!property.found) {
248
+ return undefined;
249
+ }
250
+ else if (!Array.isArray(property.value) || !property.value.every((item) => typeof item === "string")) {
251
+ throw sourceError(path, `${label} must be an array of strings`);
252
+ }
253
+ return cloneAndFreeze(property.value);
254
+ }
255
+ function optionalCreatedAt(event, names, path) {
256
+ const property = readProperty(event, names);
257
+ if (!property.found || property.value === null) {
258
+ return undefined;
259
+ }
260
+ else if (property.value instanceof Date) {
261
+ return canonicalDateTimestamp(property.value, path);
262
+ }
263
+ else if (typeof property.value === "string") {
264
+ return canonicalIsoTimestamp(property.value, path);
265
+ }
266
+ return canonicalProtobufTimestamp(property.value, path);
267
+ }
268
+ function canonicalIsoTimestamp(value, path) {
269
+ const match = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,9}))?Z$/.exec(value);
270
+ if (match === null) {
271
+ throw sourceError(path, "created at must be a UTC ISO-8601 timestamp");
272
+ }
273
+ const milliseconds = (match[2] ?? "").padEnd(3, "0").slice(0, 3);
274
+ const date = new Date(`${match[1]}.${milliseconds}Z`);
275
+ if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 19) !== match[1]) {
276
+ throw sourceError(path, "created at must be a valid timestamp");
277
+ }
278
+ requireLedgerTimestampSeconds(BigInt(Math.floor(date.getTime() / 1000)), path);
279
+ return `${match[1]}.${(match[2] ?? "").padEnd(9, "0")}Z`;
280
+ }
281
+ function canonicalProtobufTimestamp(value, path) {
282
+ const timestamp = asObject(value);
283
+ const seconds = timestamp === undefined ? undefined : readProperty(timestamp, ["seconds"]).value;
284
+ const nanos = timestamp === undefined ? undefined : readProperty(timestamp, ["nanos"]).value;
285
+ if (typeof seconds !== "string" || !/^-?\d+$/.test(seconds) || typeof nanos !== "number" || !Number.isSafeInteger(nanos) || nanos < 0 || nanos > 999999999) {
286
+ throw sourceError(path, "created at must be a valid timestamp");
287
+ }
288
+ const secondsValue = BigInt(seconds);
289
+ requireLedgerTimestampSeconds(secondsValue, path);
290
+ const date = new Date(Number(secondsValue * 1000n));
291
+ if (Number.isNaN(date.getTime())) {
292
+ throw sourceError(path, "created at must be a valid timestamp");
293
+ }
294
+ const base = date.toISOString().replace(".000Z", "");
295
+ return `${base}.${nanos.toString().padStart(9, "0")}Z`;
296
+ }
297
+ function canonicalDateTimestamp(value, path) {
298
+ const milliseconds = value.getTime();
299
+ if (Number.isNaN(milliseconds)) {
300
+ throw sourceError(path, "created at must be a valid timestamp");
301
+ }
302
+ requireLedgerTimestampSeconds(BigInt(Math.floor(milliseconds / 1000)), path);
303
+ return value.toISOString().replace(/\.(\d{3})Z$/, (_match, milliseconds) => `.${milliseconds}000000Z`);
304
+ }
305
+ function requireLedgerTimestampSeconds(seconds, path) {
306
+ if (seconds < DAML_MIN_TIMESTAMP_SECONDS || seconds > DAML_MAX_TIMESTAMP_SECONDS) {
307
+ throw sourceError(path, "created at must be within DAML timestamp bounds");
308
+ }
309
+ }
310
+ function readProperty(object, names) {
311
+ for (const name of names) {
312
+ if (Object.prototype.hasOwnProperty.call(object, name) && object[name] !== undefined) {
313
+ return { found: true, value: object[name] };
314
+ }
315
+ }
316
+ return { found: false };
317
+ }
318
+ function hasValue(object, name) {
319
+ return Object.prototype.hasOwnProperty.call(object, name) && object[name] !== undefined;
320
+ }
321
+ function objectOrThrow(value, path, detail) {
322
+ const object = asObject(value);
323
+ if (object === undefined) {
324
+ throw sourceError(path, detail);
325
+ }
326
+ return object;
327
+ }
328
+ function asObject(value) {
329
+ return value !== null && typeof value === "object" && !Array.isArray(value)
330
+ ? value
331
+ : undefined;
332
+ }
333
+ function stringValue(value) {
334
+ return typeof value === "string" && value.length > 0 ? value : undefined;
335
+ }
336
+ function cloneAndFreeze(value, seen = new WeakMap()) {
337
+ if (value === null || typeof value !== "object") {
338
+ return value;
339
+ }
340
+ else if (value instanceof Date) {
341
+ return Object.freeze(new Date(value.getTime()));
342
+ }
343
+ const existing = seen.get(value);
344
+ if (existing !== undefined) {
345
+ return existing;
346
+ }
347
+ const output = Array.isArray(value)
348
+ ? []
349
+ : Object.create(Object.getPrototypeOf(value));
350
+ seen.set(value, output);
351
+ for (const key of Reflect.ownKeys(value)) {
352
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
353
+ if (descriptor !== undefined && "value" in descriptor) {
354
+ Object.defineProperty(output, key, { ...descriptor, value: cloneAndFreeze(descriptor.value, seen) });
355
+ }
356
+ }
357
+ return Object.freeze(output);
358
+ }
359
+ function removeUndefined(value) {
360
+ return Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
361
+ }
362
+ function sourceError(path, detail) {
363
+ return new DamlMaterializationError(path, detail);
364
+ }
@@ -0,0 +1,5 @@
1
+ /** Raised when a transport value cannot be materialized as its DAML descriptor. */
2
+ export declare class DamlMaterializationError extends Error {
3
+ readonly path: string;
4
+ constructor(path: string, detail: string);
5
+ }
@@ -0,0 +1,9 @@
1
+ /** Raised when a transport value cannot be materialized as its DAML descriptor. */
2
+ export class DamlMaterializationError extends Error {
3
+ path;
4
+ constructor(path, detail) {
5
+ super(`${path}: ${detail}`);
6
+ this.name = "DamlMaterializationError";
7
+ this.path = path;
8
+ }
9
+ }
@@ -0,0 +1,6 @@
1
+ /** Base class for generated DAML template bindings. */
2
+ export declare class DamlTemplate {
3
+ #private;
4
+ constructor(contractId: string);
5
+ get contractId(): string;
6
+ }
@@ -0,0 +1,10 @@
1
+ /** Base class for generated DAML template bindings. */
2
+ export class DamlTemplate {
3
+ #contractId;
4
+ constructor(contractId) {
5
+ this.#contractId = contractId;
6
+ }
7
+ get contractId() {
8
+ return this.#contractId;
9
+ }
10
+ }
@@ -0,0 +1,71 @@
1
+ import { Value } from "../../transports/grpc/generated/canton/com/daml/ledger/api/v2/value.js";
2
+ export type DamlTypeIdentity = {
3
+ readonly packageId: string;
4
+ readonly moduleName: string;
5
+ readonly entityName: string;
6
+ };
7
+ export type DamlPrimitiveType = "unit" | "bool" | "int64" | "date" | "timestamp" | "numeric" | "party" | "text";
8
+ export type DamlPrimitiveDescriptor = {
9
+ readonly kind: "primitive";
10
+ readonly primitive: DamlPrimitiveType;
11
+ readonly numericScale?: number;
12
+ };
13
+ export type DamlContractIdDescriptor = {
14
+ readonly kind: "contractId";
15
+ readonly contract?: DamlTypeDescriptor;
16
+ };
17
+ export type DamlOptionalDescriptor = {
18
+ readonly kind: "optional";
19
+ readonly element: DamlTypeDescriptor;
20
+ };
21
+ export type DamlListDescriptor = {
22
+ readonly kind: "list";
23
+ readonly element: DamlTypeDescriptor;
24
+ };
25
+ export type DamlTextMapDescriptor = {
26
+ readonly kind: "textMap";
27
+ readonly value: DamlTypeDescriptor;
28
+ };
29
+ export type DamlGenMapDescriptor = {
30
+ readonly kind: "genMap";
31
+ readonly key: DamlTypeDescriptor;
32
+ readonly value: DamlTypeDescriptor;
33
+ };
34
+ export type DamlRecordFieldDescriptor = {
35
+ readonly damlLabel: string;
36
+ readonly propertyName: string;
37
+ readonly type: DamlTypeDescriptor;
38
+ };
39
+ export type DamlRecordDescriptor = {
40
+ readonly kind: "record";
41
+ readonly fields: readonly DamlRecordFieldDescriptor[];
42
+ };
43
+ export type DamlVariantConstructorDescriptor = {
44
+ readonly constructor: string;
45
+ readonly payload: DamlTypeDescriptor;
46
+ };
47
+ export type DamlVariantDescriptor = {
48
+ readonly kind: "variant";
49
+ readonly constructors: readonly DamlVariantConstructorDescriptor[];
50
+ };
51
+ export type DamlEnumDescriptor = {
52
+ readonly kind: "enum";
53
+ readonly constructors: readonly string[];
54
+ };
55
+ export type DamlNamedReferenceDescriptor = {
56
+ readonly kind: "namedReference";
57
+ readonly identity: DamlTypeIdentity;
58
+ };
59
+ /** A closed description of a serializable DAML value. */
60
+ export type DamlTypeDescriptor = DamlPrimitiveDescriptor | DamlContractIdDescriptor | DamlOptionalDescriptor | DamlListDescriptor | DamlTextMapDescriptor | DamlGenMapDescriptor | DamlRecordDescriptor | DamlVariantDescriptor | DamlEnumDescriptor | DamlNamedReferenceDescriptor;
61
+ /** Resolves named descriptors lazily so recursive data types remain finite. */
62
+ export type DamlTypeDescriptorRegistry = {
63
+ readonly resolve: (identity: DamlTypeIdentity) => (() => DamlTypeDescriptor) | undefined;
64
+ };
65
+ export type DamlValueSource = {
66
+ readonly kind: "protobuf";
67
+ readonly value: Value;
68
+ } | {
69
+ readonly kind: "json";
70
+ readonly value: unknown;
71
+ };
@@ -0,0 +1,7 @@
1
+ import { DamlDate, DamlEnum, DamlGenMap, DamlRecord, DamlTextMap, DamlTimestamp, DamlUnit, DamlVariant } from "../../core/types/daml-values.js";
2
+ import { DamlNumeric } from "../../core/types/daml-numeric.js";
3
+ import { DamlParty } from "../../core/types/daml-party.js";
4
+ import { DamlTypeDescriptor, DamlTypeDescriptorRegistry, DamlValueSource } from "./daml-type-descriptor.js";
5
+ export type DamlDecodedValue = DamlUnit | boolean | bigint | DamlDate | DamlTimestamp | DamlNumeric | DamlParty | string | undefined | readonly DamlDecodedValue[] | DamlTextMap | DamlGenMap | DamlRecord | DamlVariant | DamlEnum;
6
+ /** Decodes a protobuf or JSON/PQS DAML value according to its generated descriptor. */
7
+ export declare function decodeDamlValue(source: DamlValueSource, descriptor: DamlTypeDescriptor, registry: DamlTypeDescriptorRegistry, path: string): DamlDecodedValue;