@c7-digital/ledger 0.0.2

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 (98) hide show
  1. package/BUILD.md +125 -0
  2. package/LICENSE +17 -0
  3. package/README.md +97 -0
  4. package/lib/scripts/build.d.ts +9 -0
  5. package/lib/scripts/build.js +366 -0
  6. package/lib/scripts/enhance-types.d.ts +3 -0
  7. package/lib/scripts/enhance-types.js +174 -0
  8. package/lib/scripts/generate-asyncapi-types.d.ts +9 -0
  9. package/lib/scripts/generate-asyncapi-types.js +129 -0
  10. package/lib/scripts/generate-schema-modules.d.ts +3 -0
  11. package/lib/scripts/generate-schema-modules.js +33 -0
  12. package/lib/src/TemplateEmitterMap.d.ts +40 -0
  13. package/lib/src/TemplateEmitterMap.js +57 -0
  14. package/lib/src/client.d.ts +55 -0
  15. package/lib/src/client.js +62 -0
  16. package/lib/src/generated/api.d.ts +7147 -0
  17. package/lib/src/generated/api.js +1 -0
  18. package/lib/src/generated/async-api.d.ts +1665 -0
  19. package/lib/src/generated/async-api.js +1 -0
  20. package/lib/src/generated/asyncapi-schema.d.ts +1 -0
  21. package/lib/src/generated/asyncapi-schema.js +2233 -0
  22. package/lib/src/generated/openapi-schema.d.ts +1 -0
  23. package/lib/src/generated/openapi-schema.js +7321 -0
  24. package/lib/src/generated/sdk-version.d.ts +1 -0
  25. package/lib/src/generated/sdk-version.js +3 -0
  26. package/lib/src/index.d.ts +8 -0
  27. package/lib/src/index.js +8 -0
  28. package/lib/src/ledger.d.ts +188 -0
  29. package/lib/src/ledger.js +849 -0
  30. package/lib/src/ledger.test.d.ts +1 -0
  31. package/lib/src/ledger.test.js +23 -0
  32. package/lib/src/logger.d.ts +41 -0
  33. package/lib/src/logger.js +56 -0
  34. package/lib/src/multistream.d.ts +47 -0
  35. package/lib/src/multistream.js +123 -0
  36. package/lib/src/translate.d.ts +5 -0
  37. package/lib/src/translate.js +30 -0
  38. package/lib/src/types.d.ts +201 -0
  39. package/lib/src/types.js +1 -0
  40. package/lib/src/util.d.ts +3 -0
  41. package/lib/src/util.js +7 -0
  42. package/lib/src/validation.d.ts +27 -0
  43. package/lib/src/validation.js +182 -0
  44. package/lib/src/valueTypes.d.ts +34 -0
  45. package/lib/src/valueTypes.js +76 -0
  46. package/lib/src/websocket.d.ts +69 -0
  47. package/lib/src/websocket.js +125 -0
  48. package/lib/tsconfig.tsbuildinfo +1 -0
  49. package/lib-lite/scripts/build.d.ts +9 -0
  50. package/lib-lite/scripts/build.js +366 -0
  51. package/lib-lite/scripts/enhance-types.d.ts +3 -0
  52. package/lib-lite/scripts/enhance-types.js +174 -0
  53. package/lib-lite/scripts/generate-asyncapi-types.d.ts +9 -0
  54. package/lib-lite/scripts/generate-asyncapi-types.js +129 -0
  55. package/lib-lite/scripts/generate-schema-modules.d.ts +3 -0
  56. package/lib-lite/scripts/generate-schema-modules.js +33 -0
  57. package/lib-lite/src/TemplateEmitterMap.d.ts +40 -0
  58. package/lib-lite/src/TemplateEmitterMap.js +57 -0
  59. package/lib-lite/src/client.d.ts +55 -0
  60. package/lib-lite/src/client.js +62 -0
  61. package/lib-lite/src/generated/api.d.ts +7147 -0
  62. package/lib-lite/src/generated/api.js +1 -0
  63. package/lib-lite/src/generated/async-api.d.ts +1665 -0
  64. package/lib-lite/src/generated/async-api.js +1 -0
  65. package/lib-lite/src/generated/asyncapi-schema.d.ts +1 -0
  66. package/lib-lite/src/generated/asyncapi-schema.js +2 -0
  67. package/lib-lite/src/generated/openapi-schema.d.ts +1 -0
  68. package/lib-lite/src/generated/openapi-schema.js +2 -0
  69. package/lib-lite/src/generated/sdk-version.d.ts +1 -0
  70. package/lib-lite/src/generated/sdk-version.js +3 -0
  71. package/lib-lite/src/index.d.ts +8 -0
  72. package/lib-lite/src/index.js +8 -0
  73. package/lib-lite/src/ledger.d.ts +188 -0
  74. package/lib-lite/src/ledger.js +849 -0
  75. package/lib-lite/src/ledger.test.d.ts +1 -0
  76. package/lib-lite/src/ledger.test.js +23 -0
  77. package/lib-lite/src/logger.d.ts +41 -0
  78. package/lib-lite/src/logger.js +56 -0
  79. package/lib-lite/src/multistream.d.ts +47 -0
  80. package/lib-lite/src/multistream.js +123 -0
  81. package/lib-lite/src/translate.d.ts +5 -0
  82. package/lib-lite/src/translate.js +30 -0
  83. package/lib-lite/src/types.d.ts +201 -0
  84. package/lib-lite/src/types.js +1 -0
  85. package/lib-lite/src/util.d.ts +3 -0
  86. package/lib-lite/src/util.js +7 -0
  87. package/lib-lite/src/validation.d.ts +14 -0
  88. package/lib-lite/src/validation.js +31 -0
  89. package/lib-lite/src/valueTypes.d.ts +34 -0
  90. package/lib-lite/src/valueTypes.js +76 -0
  91. package/lib-lite/src/websocket.d.ts +69 -0
  92. package/lib-lite/src/websocket.js +125 -0
  93. package/lib-lite/tsconfig.temp.tsbuildinfo +1 -0
  94. package/package.json +72 -0
  95. package/scripts/build.ts +456 -0
  96. package/scripts/enhance-types.ts +223 -0
  97. package/scripts/generate-asyncapi-types.ts +158 -0
  98. package/scripts/generate-schema-modules.ts +52 -0
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "3.4.7";
@@ -0,0 +1,3 @@
1
+ // Auto-generated file - do not edit manually
2
+ // Generated from SDK version: 3.4.7
3
+ export const SDK_VERSION = "3.4.7";
@@ -0,0 +1,8 @@
1
+ export { Ledger, type LedgerOptions, createCmd, createAndExerciseCmd, exerciseCmd } from "./ledger.js";
2
+ export { TypedHttpClient, type TypedHttpClientConfig } from "./client.js";
3
+ export { WebSocketClient, type StreamConfig, type CompletionStreamRequest, type CompletionStreamMessage, type ActiveContractsStreamRequest, type ActiveContractsStreamMessage, type UpdatesStreamRequest, type UpdatesStreamMessage, } from "./websocket.js";
4
+ export { type ValidationMode } from "./validation.js";
5
+ export { type Logger, ConsoleLogger, NoOpLogger, logger, setLogger } from "./logger.js";
6
+ export * from "./types.js";
7
+ export * from "./valueTypes.js";
8
+ export { SDK_VERSION } from "./generated/sdk-version.js";
@@ -0,0 +1,8 @@
1
+ // Main export for the new ledger package
2
+ export { Ledger, createCmd, createAndExerciseCmd, exerciseCmd } from "./ledger.js";
3
+ export { TypedHttpClient } from "./client.js";
4
+ export { WebSocketClient, } from "./websocket.js";
5
+ export { ConsoleLogger, NoOpLogger, logger, setLogger } from "./logger.js";
6
+ export * from "./types.js";
7
+ export * from "./valueTypes.js";
8
+ export { SDK_VERSION } from "./generated/sdk-version.js";
@@ -0,0 +1,188 @@
1
+ /**
2
+ * High-level Daml Ledger abstraction for Canton's OpenAPI v2 JSON API
3
+ *
4
+ * This class provides convenient, Template and Choice-aware methods for common
5
+ * Daml operations. It applies business logic to filter and transform raw API
6
+ * responses into the expected Daml types, ensuring results match the requested
7
+ * Template or Choice specifications.
8
+ *
9
+ * Key features:
10
+ * - Template-typed contract queries and creation
11
+ * - Choice-typed exercise operations
12
+ * - Automatic filtering of irrelevant data (non-active contracts, wrong templates)
13
+ * - Type safety with branded value.proto string types
14
+ * - Compatibility with @daml/types interfaces
15
+ *
16
+ * Use this for most Daml application needs. Use TypedHttpClient directly when
17
+ * you need access to Canton-specific endpoints or full control over API calls.
18
+ */
19
+ import { ContractId, Party, Choice, InterfaceCompanion, Template, TemplateOrInterface } from "@daml/types";
20
+ import { AllocatePartyRequest, AllocatePartyResponse, Command, CreateCommand, CreateAndExerciseCommand, CreateEvent, ExerciseCommand, Event, Interface, LedgerOffset, Stream, PartyDetails, User, MultiStream, TemplateMapping, VersionedRegistry } from "./types.js";
21
+ import { ValidationMode } from "./validation.js";
22
+ import { PackageIdString } from "./valueTypes.js";
23
+ export declare function createCmd<T extends object, K = unknown>(template: Template<T, K, string>, payload: T): CreateCommand<T, K>;
24
+ export declare function createAndExerciseCmd<T extends object, C, R, K = unknown>(template: Template<T, K, string>, payload: T, choice: Choice<T, C, R, K>, argument: C): CreateAndExerciseCommand<T, C, R, K>;
25
+ export declare function exerciseCmd<T extends object, C, R, K = unknown>(contractId: ContractId<T>, choice: Choice<T, C, R, K>, argument: C): ExerciseCommand<T, C, R, K>;
26
+ /**
27
+ * Options for the Ledger constructor
28
+ */
29
+ export interface LedgerOptions {
30
+ /**
31
+ * The authentication token to use for requests
32
+ */
33
+ token: string;
34
+ /**
35
+ * The base URL for HTTP requests.
36
+ */
37
+ httpBaseUrl: string;
38
+ /**
39
+ * The base URL for WebSocket requests, derived from httpBaseUrl if not provided.
40
+ */
41
+ wsBaseUrl?: string;
42
+ /**
43
+ * The validation mode to use for requests.
44
+ * "throwOnError" - throw an error if validation fails
45
+ * "logErrors" - log errors to console/logger if validation fails
46
+ *
47
+ * The API does fail validation pretty frequently so even with "logErrors"
48
+ * please be prepared for some noise in the logger.
49
+ */
50
+ validation?: ValidationMode;
51
+ /**
52
+ * The path to the OpenAPI schema to use for validation
53
+ */
54
+ openApiSchemaPath?: string;
55
+ /**
56
+ * The path to the AsyncAPI schema to use for validation
57
+ */
58
+ asyncApiSchemaPath?: string;
59
+ /**
60
+ * Semi-optional version-aware template/interface registry.
61
+ * If provided, this function will be used instead of the default lookupTemplate.
62
+ * Should return VersionedLookupResult or undefined. This is required for
63
+ * querying and decoding interfaces views.
64
+ */
65
+ versionedRegistry?: VersionedRegistry;
66
+ }
67
+ /**
68
+ * Meant to be a simple replacement for Ledger from @daml/ledger
69
+ */
70
+ export declare class Ledger {
71
+ private client;
72
+ private ledgerEndCache?;
73
+ private ledgerEndPromise?;
74
+ private tokenUserId;
75
+ private tokenUserInfo;
76
+ private httpBaseUrl;
77
+ private options;
78
+ constructor(options: LedgerOptions);
79
+ private generateCommandId;
80
+ private resolveOffset;
81
+ private getLedgerEnd;
82
+ getTokenUserId(): string;
83
+ getTokenUserInfo(): Promise<User | null>;
84
+ getTokenActAsParties(): Promise<Party[]>;
85
+ /**
86
+ * Query for the Active Contract Set of a specific template.
87
+ * @param template a Template instance as generated by the codegen
88
+ * @param atOffset Whether we want to get historical or just the current
89
+ * state, default.
90
+ * @param includeCreatedEventBlob
91
+ * @param verbose
92
+ * @param readAsParties
93
+ * @returns
94
+ */
95
+ query<T extends object, K = unknown>(template: Template<T, K, PackageIdString>, atOffset?: LedgerOffset, includeCreatedEventBlob?: boolean, verbose?: boolean, readAsParties?: Party[]): Promise<CreateEvent<T, K>[]>;
96
+ /**
97
+ * Query for instances of a given interface.
98
+ * @param interface_
99
+ * @param atOffset
100
+ * @param includeCreatedEventBlob
101
+ * @param verbose
102
+ * @param readAsParties
103
+ * @returns
104
+ */
105
+ queryInterface<I extends object, K = unknown>(interface_: InterfaceCompanion<I, K, PackageIdString>, atOffset?: LedgerOffset, includeCreatedEventBlob?: boolean, verbose?: boolean, readAsParties?: Party[]): Promise<Interface<I>[]>;
106
+ /**
107
+ * Create a template
108
+ * @param template
109
+ * @param payload
110
+ * @param actAs
111
+ * @returns
112
+ */
113
+ create<T extends object, K = unknown, TTemplateId extends string = string>(template: Template<T, K, TTemplateId>, payload: T, actAs?: Party[]): Promise<CreateEvent<T, K>>;
114
+ /**
115
+ * Exercise a choice of a given contract
116
+ * @param choice
117
+ * @param contractId
118
+ * @param argument
119
+ * @param actAs
120
+ * @returns
121
+ */
122
+ exercise<T extends object, C, R, K = unknown>(choice: Choice<T, C, R, K>, contractId: ContractId<T>, argument: C, actAs?: Party[]): Promise<Event<object, unknown>[]>;
123
+ /**
124
+ * `submit` allows combining multiple commands into a single Canton
125
+ * transaction. Similar to `create` and `exercise` one can use `createCmd`
126
+ * and `exerciseCmd` to create commands, that are then passed to `submit`.
127
+ *
128
+ * @param commands
129
+ * @param actAs Defaults to the actAs parties of the user in the token.
130
+ * @returns Stream of events resulting from the submitted commands.
131
+ */
132
+ submit(commands: Command<any, any>[], actAs?: Party[]): Promise<Event<object, unknown>[]>;
133
+ private initClient;
134
+ /**
135
+ * Stream functionality using WebSockets
136
+ *
137
+ * @param template The template to stream
138
+ * @param readAsParties Array of parties to stream for, if not specified default to
139
+ * the actAs parties of the user in the token.
140
+ * @param offset Optional offset to start streaming from
141
+ * @param skipAcs Whether to skip archived contracts
142
+ * @param includeCreatedEventBlob Whether to include created event blobs
143
+ * @returns A stream of events for the specified template
144
+ */
145
+ streamQuery<T extends object, K = unknown>(template: TemplateOrInterface<T, K>, offset?: LedgerOffset, skipAcs?: boolean, includeCreatedEventBlob?: boolean, readAsParties?: Party[]): Promise<Stream<T, K>>;
146
+ /**
147
+ * Create a type-safe MultiStream for working with multiple templates
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Define your template mapping
152
+ * type MyTemplates = {
153
+ * [UserTemplate.templateId]: { contractType: UserContract, keyType: UserKey },
154
+ * [AccountTemplate.templateId]: { contractType: AccountContract, keyType: AccountKey }
155
+ * };
156
+ *
157
+ * // Create a type-safe multi-stream
158
+ * const stream = await ledger.createMultiStream<MyTemplates>(
159
+ * [UserTemplate, AccountTemplate],
160
+ * [party]
161
+ * );
162
+ *
163
+ * // Use template-specific handlers with proper typing
164
+ * stream.onCreate(UserTemplate.templateId, (event) => {
165
+ * // event.payload is typed as UserContract
166
+ * logger.log("User created:", event.payload.username);
167
+ * });
168
+ *
169
+ * stream.onCreate(AccountTemplate.templateId, (event) => {
170
+ * // event.payload is typed as AccountContract
171
+ * logger.log("Account created:", event.payload.accountNumber);
172
+ * });
173
+ *
174
+ * stream.start();
175
+ * ```
176
+ *
177
+ * @param templates Array of templates to stream
178
+ * @param offset Optional offset to start streaming from
179
+ * @param includeCreatedEventBlob Whether to include created event blobs
180
+ * @param readAsParties Array of parties to stream for, if not specified default to
181
+ * the actAs parties of the user in the token.
182
+ * @returns A type-safe MultiStream for working with multiple templates
183
+ */
184
+ createMultiStream<TM extends TemplateMapping>(tm: TM, offset?: LedgerOffset, skipAcs?: boolean, includeCreatedEventBlob?: boolean, readAsParties?: Party[]): Promise<MultiStream<TM>>;
185
+ getUserInfo(userId: string): Promise<User | null>;
186
+ getParties(): Promise<PartyDetails[]>;
187
+ allocateParty(request: AllocatePartyRequest): Promise<AllocatePartyResponse>;
188
+ }