@fairmint/canton-node-sdk 0.0.272 → 0.0.273
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.
- package/README.md +26 -0
- package/build/src/clients/ledger-json-api/LedgerJsonApiClient.generated.d.ts +18 -1
- package/build/src/clients/ledger-json-api/LedgerJsonApiClient.generated.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/LedgerJsonApiClient.generated.js +8 -0
- package/build/src/clients/ledger-json-api/LedgerJsonApiClient.generated.js.map +1 -1
- package/build/src/clients/ledger-json-api/index.d.ts +6 -1
- package/build/src/clients/ledger-json-api/index.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/index.js +9 -1
- package/build/src/clients/ledger-json-api/index.js.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/commands/async/submit.d.ts +52 -52
- package/build/src/clients/ledger-json-api/operations/v2/commands/submit-and-wait.d.ts +52 -52
- package/build/src/clients/ledger-json-api/operations/v2/commands/subscribe-to-raw-completions.d.ts +66 -0
- package/build/src/clients/ledger-json-api/operations/v2/commands/subscribe-to-raw-completions.d.ts.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/commands/subscribe-to-raw-completions.js +65 -0
- package/build/src/clients/ledger-json-api/operations/v2/commands/subscribe-to-raw-completions.js.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/events/get-events-by-contract-id.d.ts +26 -3
- package/build/src/clients/ledger-json-api/operations/v2/events/get-events-by-contract-id.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/events/get-events-by-contract-id.js +36 -5
- package/build/src/clients/ledger-json-api/operations/v2/events/get-events-by-contract-id.js.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/state/active-contracts-request.d.ts +17 -3
- package/build/src/clients/ledger-json-api/operations/v2/state/active-contracts-request.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/state/active-contracts-request.js +24 -7
- package/build/src/clients/ledger-json-api/operations/v2/state/active-contracts-request.js.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-update-by-id.d.ts +37 -2
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-update-by-id.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-update-by-id.js +42 -23
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-update-by-id.js.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-updates-page.d.ts +503 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-updates-page.d.ts.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-updates-page.js +178 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/get-updates-page.js.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-raw-updates.d.ts +87 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-raw-updates.d.ts.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-raw-updates.js +99 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-raw-updates.js.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-updates.d.ts +31 -2
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-updates.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-updates.js +38 -7
- package/build/src/clients/ledger-json-api/operations/v2/updates/subscribe-to-updates.js.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/utils/event-format-builder.d.ts +68 -20
- package/build/src/clients/ledger-json-api/operations/v2/utils/event-format-builder.d.ts.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/utils/event-format-builder.js +76 -50
- package/build/src/clients/ledger-json-api/operations/v2/utils/event-format-builder.js.map +1 -1
- package/build/src/clients/ledger-json-api/operations/v2/utils/party-scope.d.ts +36 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/party-scope.d.ts.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/party-scope.js +45 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/party-scope.js.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.d.ts +113 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.d.ts.map +1 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.js +295 -0
- package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.js.map +1 -0
- package/build/src/core/http/HttpClient.d.ts +5 -0
- package/build/src/core/http/HttpClient.d.ts.map +1 -1
- package/build/src/core/http/HttpClient.js +40 -11
- package/build/src/core/http/HttpClient.js.map +1 -1
- package/build/src/core/operations/WebSocketOperationFactory.js +1 -1
- package/build/src/core/operations/WebSocketOperationFactory.js.map +1 -1
- package/build/src/core/types.d.ts +6 -0
- package/build/src/core/types.d.ts.map +1 -1
- package/build/src/core/utils/index.d.ts +1 -0
- package/build/src/core/utils/index.d.ts.map +1 -1
- package/build/src/core/utils/index.js +7 -1
- package/build/src/core/utils/index.js.map +1 -1
- package/build/src/core/utils/lossless-json.d.ts +52 -0
- package/build/src/core/utils/lossless-json.d.ts.map +1 -0
- package/build/src/core/utils/lossless-json.js +250 -0
- package/build/src/core/utils/lossless-json.js.map +1 -0
- package/build/src/core/ws/WebSocketClient.d.ts +5 -1
- package/build/src/core/ws/WebSocketClient.d.ts.map +1 -1
- package/build/src/core/ws/WebSocketClient.js +1 -1
- package/build/src/core/ws/WebSocketClient.js.map +1 -1
- package/build/src/utils/ledger/user-rights.d.ts +46 -0
- package/build/src/utils/ledger/user-rights.d.ts.map +1 -1
- package/build/src/utils/ledger/user-rights.js +68 -0
- package/build/src/utils/ledger/user-rights.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,30 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared utility for building eventFormat configuration used across multiple Ledger JSON API operations. This module
|
|
3
3
|
* provides a consistent way to construct the complex eventFormat structure from simple parameters.
|
|
4
|
+
*
|
|
5
|
+
* Every builder reads either a party list or every party: {@link EventFormatBuilderParams} (`{ parties: [...] }`) builds
|
|
6
|
+
* `filtersByParty`, and {@link AnyPartyEventFormatBuilderParams} (`{ anyParty: true }`) builds `filtersForAnyParty`,
|
|
7
|
+
* which reads as every party the participant hosts. The types reject an object with both keys, and so do the builders
|
|
8
|
+
* at run time.
|
|
4
9
|
*/
|
|
5
10
|
import type { TransactionFormat, TransactionShape, UpdateFormat } from '../../../schemas/operations/updates';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
export type { AnyPartyScope, PartiesScope, PartyScope } from './party-scope';
|
|
12
|
+
/** Filter options shared by every format builder, apart from whose events are read. */
|
|
13
|
+
export interface EventFilterOptions {
|
|
9
14
|
/** Optional template filters applied server-side. */
|
|
10
15
|
templateIds?: string[] | undefined;
|
|
11
16
|
/** Optional interface filters applied server-side. */
|
|
12
17
|
interfaceIds?: string[] | undefined;
|
|
13
18
|
/** Include interface views in InterfaceFilter results (default true). */
|
|
14
19
|
includeInterfaceView?: boolean | undefined;
|
|
15
|
-
/** Include created event blobs in template and
|
|
20
|
+
/** Include created event blobs in template, interface and wildcard filter results (default false). */
|
|
16
21
|
includeCreatedEventBlob?: boolean | undefined;
|
|
22
|
+
/** Ask for verbose values (record field labels and type ids) (default false). */
|
|
23
|
+
verbose?: boolean | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Party-list parameters of {@link buildEventFormat} (`filtersByParty`). */
|
|
26
|
+
export interface EventFormatBuilderParams extends EventFilterOptions {
|
|
27
|
+
/** List of parties to scope the filter. At least one party is required. */
|
|
28
|
+
parties: string[];
|
|
29
|
+
/** Not allowed with `parties`: pass {@link AnyPartyEventFormatBuilderParams} to read as every party instead. */
|
|
30
|
+
anyParty?: never;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Any-party parameters of {@link buildEventFormat} (`filtersForAnyParty`): every party the participant hosts, including
|
|
34
|
+
* parties allocated later. Needs the user's `CanReadAsAnyParty` right.
|
|
35
|
+
*/
|
|
36
|
+
export interface AnyPartyEventFormatBuilderParams extends EventFilterOptions {
|
|
37
|
+
/** Read as every party the participant hosts. */
|
|
38
|
+
anyParty: true;
|
|
39
|
+
/** Not allowed with `anyParty`. */
|
|
40
|
+
parties?: never;
|
|
17
41
|
}
|
|
18
42
|
export type TransactionFormatBuilderParams = EventFormatBuilderParams & {
|
|
19
43
|
/** Transaction shape (default TRANSACTION_SHAPE_LEDGER_EFFECTS). */
|
|
20
44
|
transactionShape?: TransactionShape | undefined;
|
|
21
45
|
};
|
|
46
|
+
/** {@link buildTransactionFormat} for every party the participant hosts; see {@link AnyPartyEventFormatBuilderParams}. */
|
|
47
|
+
export type AnyPartyTransactionFormatBuilderParams = AnyPartyEventFormatBuilderParams & {
|
|
48
|
+
/** Transaction shape (default TRANSACTION_SHAPE_LEDGER_EFFECTS). */
|
|
49
|
+
transactionShape?: TransactionShape | undefined;
|
|
50
|
+
};
|
|
22
51
|
export type UpdateFormatBuilderParams = TransactionFormatBuilderParams & {
|
|
23
52
|
/** Include reassignments with the same filters (default true). */
|
|
24
53
|
includeReassignments?: boolean | undefined;
|
|
25
54
|
/** Include participant authorization topology events for the parties (default false). */
|
|
26
55
|
includeTopologyEvents?: boolean | undefined;
|
|
27
56
|
};
|
|
57
|
+
/** {@link buildUpdateFormat} for every party the participant hosts; see {@link AnyPartyEventFormatBuilderParams}. */
|
|
58
|
+
export type AnyPartyUpdateFormatBuilderParams = AnyPartyTransactionFormatBuilderParams & {
|
|
59
|
+
/** Include reassignments with the same filters (default true). */
|
|
60
|
+
includeReassignments?: boolean | undefined;
|
|
61
|
+
/** Include participant authorization topology events for every party (default false). */
|
|
62
|
+
includeTopologyEvents?: boolean | undefined;
|
|
63
|
+
};
|
|
28
64
|
type FilterCumulative = Array<{
|
|
29
65
|
identifierFilter: {
|
|
30
66
|
TemplateFilter: {
|
|
@@ -53,37 +89,49 @@ type FilterCumulative = Array<{
|
|
|
53
89
|
};
|
|
54
90
|
};
|
|
55
91
|
}>;
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
* creating filtersByParty configurations from simple parameters.
|
|
59
|
-
*
|
|
60
|
-
* @param params - Configuration parameters for building the event format
|
|
61
|
-
* @returns An eventFormat object ready to be used in API requests
|
|
62
|
-
* @throws Error if no parties are provided
|
|
63
|
-
*/
|
|
64
|
-
export declare function buildEventFormat(params: EventFormatBuilderParams): {
|
|
92
|
+
/** The event format the builders produce. `filtersForAnyParty` is present only for `{ anyParty: true }`. */
|
|
93
|
+
export interface BuiltEventFormat {
|
|
65
94
|
verbose: boolean;
|
|
95
|
+
/** One entry per listed party; empty for `{ anyParty: true }`. */
|
|
66
96
|
filtersByParty: Record<string, {
|
|
67
97
|
cumulative: FilterCumulative;
|
|
68
98
|
}>;
|
|
69
|
-
}
|
|
99
|
+
/** The filters for every party on the participant; present only for `{ anyParty: true }`. */
|
|
100
|
+
filtersForAnyParty?: {
|
|
101
|
+
cumulative: FilterCumulative;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Builds the eventFormat object structure used in various Ledger JSON API operations.
|
|
106
|
+
*
|
|
107
|
+
* - `{ parties }` builds `filtersByParty`, one entry per party. Without template or interface filters the cumulative list
|
|
108
|
+
* is empty (a wildcard), or an explicit wildcard filter when `includeCreatedEventBlob` is true.
|
|
109
|
+
* - `{ anyParty: true }` builds `filtersForAnyParty` and leaves `filtersByParty` empty. Without template or interface
|
|
110
|
+
* filters it always sends an explicit wildcard filter carrying `includeCreatedEventBlob`.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Whose events to read, and the filter options
|
|
113
|
+
* @returns An eventFormat object ready to be used in API requests
|
|
114
|
+
* @throws Error if neither a non-empty `parties` list nor `anyParty: true` is given, or if both are
|
|
115
|
+
*/
|
|
116
|
+
export declare function buildEventFormat(params: EventFormatBuilderParams | AnyPartyEventFormatBuilderParams): BuiltEventFormat;
|
|
70
117
|
/**
|
|
71
118
|
* Builds a transaction format: the event format plus a transaction shape. The result also fits the `transactionFormat`
|
|
72
119
|
* of `submitAndWaitForTransaction`.
|
|
73
120
|
*
|
|
74
121
|
* @param params - Event format parameters and an optional `transactionShape`
|
|
75
122
|
* @returns A transaction format using `TRANSACTION_SHAPE_LEDGER_EFFECTS` unless a shape is given
|
|
76
|
-
* @throws Error if
|
|
123
|
+
* @throws Error if neither a non-empty `parties` list nor `anyParty: true` is given, or if both are
|
|
77
124
|
*/
|
|
78
|
-
export declare function buildTransactionFormat(params: TransactionFormatBuilderParams): TransactionFormat;
|
|
125
|
+
export declare function buildTransactionFormat(params: TransactionFormatBuilderParams | AnyPartyTransactionFormatBuilderParams): TransactionFormat;
|
|
79
126
|
/**
|
|
80
127
|
* Builds the update format that `subscribeToUpdates` sends, so it can also be passed as the `updateFormat` of
|
|
81
|
-
* `getUpdateByOffset
|
|
128
|
+
* `getUpdateByOffset`, `getUpdatesPage`, `getRawUpdatesPage` and `subscribeToRawUpdates`. Reassignments reuse the same
|
|
129
|
+
* filters. Topology events cover the same parties: the listed ones, or, with `anyParty`, every party (an empty
|
|
130
|
+
* participant-authorization format, which the Ledger API reads as all parties).
|
|
82
131
|
*
|
|
83
132
|
* @param params - Transaction format parameters and the optional reassignment and topology switches
|
|
84
133
|
* @returns An update format with transactions, reassignments (unless disabled) and topology events (when enabled)
|
|
85
|
-
* @throws Error if
|
|
134
|
+
* @throws Error if neither a non-empty `parties` list nor `anyParty: true` is given, or if both are
|
|
86
135
|
*/
|
|
87
|
-
export declare function buildUpdateFormat(params: UpdateFormatBuilderParams): UpdateFormat;
|
|
88
|
-
export {};
|
|
136
|
+
export declare function buildUpdateFormat(params: UpdateFormatBuilderParams | AnyPartyUpdateFormatBuilderParams): UpdateFormat;
|
|
89
137
|
//# sourceMappingURL=event-format-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-format-builder.d.ts","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/event-format-builder.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"event-format-builder.d.ts","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/event-format-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAE7G,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE7E,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACnC,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACpC,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3C,sGAAsG;IACtG,uBAAuB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9C,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B;AAED,4EAA4E;AAC5E,MAAM,WAAW,wBAAyB,SAAQ,kBAAkB;IAClE,2EAA2E;IAC3E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,gHAAgH;IAChH,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,gCAAiC,SAAQ,kBAAkB;IAC1E,iDAAiD;IACjD,QAAQ,EAAE,IAAI,CAAC;IACf,mCAAmC;IACnC,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB;AAED,MAAM,MAAM,8BAA8B,GAAG,wBAAwB,GAAG;IACtE,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACjD,CAAC;AAEF,0HAA0H;AAC1H,MAAM,MAAM,sCAAs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F,kBAAkB,CAAC,EAAE;QAAE,UAAU,EAAE,gBAAgB,CAAA;KAAE,CAAC;CACvD;AAgCD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,wBAAwB,GAAG,gCAAgC,GAClE,gBAAgB,CAiDlB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,8BAA8B,GAAG,sCAAsC,GAC9E,iBAAiB,CAKnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,yBAAyB,GAAG,iCAAiC,GAAG,YAAY,CAmBrH"}
|
|
@@ -2,68 +2,92 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Shared utility for building eventFormat configuration used across multiple Ledger JSON API operations. This module
|
|
4
4
|
* provides a consistent way to construct the complex eventFormat structure from simple parameters.
|
|
5
|
+
*
|
|
6
|
+
* Every builder reads either a party list or every party: {@link EventFormatBuilderParams} (`{ parties: [...] }`) builds
|
|
7
|
+
* `filtersByParty`, and {@link AnyPartyEventFormatBuilderParams} (`{ anyParty: true }`) builds `filtersForAnyParty`,
|
|
8
|
+
* which reads as every party the participant hosts. The types reject an object with both keys, and so do the builders
|
|
9
|
+
* at run time.
|
|
5
10
|
*/
|
|
6
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
12
|
exports.buildEventFormat = buildEventFormat;
|
|
8
13
|
exports.buildTransactionFormat = buildTransactionFormat;
|
|
9
14
|
exports.buildUpdateFormat = buildUpdateFormat;
|
|
15
|
+
function buildIdentifierFilters(params) {
|
|
16
|
+
const includeCreatedEventBlob = params.includeCreatedEventBlob ?? false;
|
|
17
|
+
const templateFilters = (params.templateIds ?? []).map((templateId) => ({
|
|
18
|
+
identifierFilter: {
|
|
19
|
+
TemplateFilter: {
|
|
20
|
+
value: {
|
|
21
|
+
templateId,
|
|
22
|
+
includeCreatedEventBlob,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
const interfaceFilters = (params.interfaceIds ?? []).map((interfaceId) => ({
|
|
28
|
+
identifierFilter: {
|
|
29
|
+
InterfaceFilter: {
|
|
30
|
+
value: {
|
|
31
|
+
interfaceId,
|
|
32
|
+
includeInterfaceView: params.includeInterfaceView ?? true,
|
|
33
|
+
includeCreatedEventBlob,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
return [...templateFilters, ...interfaceFilters];
|
|
39
|
+
}
|
|
40
|
+
function wildcardFilter(includeCreatedEventBlob) {
|
|
41
|
+
return [{ identifierFilter: { WildcardFilter: { value: { includeCreatedEventBlob } } } }];
|
|
42
|
+
}
|
|
10
43
|
/**
|
|
11
|
-
* Builds the eventFormat object structure used in various Ledger JSON API operations.
|
|
12
|
-
* creating filtersByParty configurations from simple parameters.
|
|
44
|
+
* Builds the eventFormat object structure used in various Ledger JSON API operations.
|
|
13
45
|
*
|
|
14
|
-
*
|
|
46
|
+
* - `{ parties }` builds `filtersByParty`, one entry per party. Without template or interface filters the cumulative list
|
|
47
|
+
* is empty (a wildcard), or an explicit wildcard filter when `includeCreatedEventBlob` is true.
|
|
48
|
+
* - `{ anyParty: true }` builds `filtersForAnyParty` and leaves `filtersByParty` empty. Without template or interface
|
|
49
|
+
* filters it always sends an explicit wildcard filter carrying `includeCreatedEventBlob`.
|
|
50
|
+
*
|
|
51
|
+
* @param params - Whose events to read, and the filter options
|
|
15
52
|
* @returns An eventFormat object ready to be used in API requests
|
|
16
|
-
* @throws Error if
|
|
53
|
+
* @throws Error if neither a non-empty `parties` list nor `anyParty: true` is given, or if both are
|
|
17
54
|
*/
|
|
18
55
|
function buildEventFormat(params) {
|
|
19
|
-
|
|
56
|
+
// The types already exclude both forms at once; JavaScript callers and casts are checked here.
|
|
57
|
+
const scope = params;
|
|
58
|
+
if (scope.anyParty !== undefined && scope.parties !== undefined) {
|
|
59
|
+
throw new Error('Pass either anyParty: true or parties to the event format builder, not both');
|
|
60
|
+
}
|
|
61
|
+
const verbose = params.verbose ?? false;
|
|
62
|
+
const identifierFilters = buildIdentifierFilters(params);
|
|
63
|
+
if (params.anyParty === true) {
|
|
64
|
+
return {
|
|
65
|
+
verbose,
|
|
66
|
+
filtersByParty: {},
|
|
67
|
+
filtersForAnyParty: {
|
|
68
|
+
cumulative: identifierFilters.length > 0 ? identifierFilters : wildcardFilter(params.includeCreatedEventBlob ?? false),
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (scope.anyParty !== undefined) {
|
|
73
|
+
throw new Error('anyParty must be true when it is given');
|
|
74
|
+
}
|
|
75
|
+
if (!Array.isArray(scope.parties) || scope.parties.length === 0) {
|
|
20
76
|
throw new Error('At least one party is required for event format filters');
|
|
21
77
|
}
|
|
22
|
-
//
|
|
78
|
+
// Fresh objects per party, as before any-party support: a caller adjusting one party's filters must not change
|
|
79
|
+
// another party's.
|
|
23
80
|
const buildCumulative = () => {
|
|
24
|
-
const includeCreatedEventBlob = params.includeCreatedEventBlob ?? false;
|
|
25
|
-
const templateFilters = (params.templateIds ?? []).map((templateId) => ({
|
|
26
|
-
identifierFilter: {
|
|
27
|
-
TemplateFilter: {
|
|
28
|
-
value: {
|
|
29
|
-
templateId,
|
|
30
|
-
includeCreatedEventBlob,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
}));
|
|
35
|
-
const interfaceFilters = (params.interfaceIds ?? []).map((interfaceId) => ({
|
|
36
|
-
identifierFilter: {
|
|
37
|
-
InterfaceFilter: {
|
|
38
|
-
value: {
|
|
39
|
-
interfaceId,
|
|
40
|
-
includeInterfaceView: params.includeInterfaceView ?? true,
|
|
41
|
-
includeCreatedEventBlob,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}));
|
|
46
|
-
const identifierFilters = [...templateFilters, ...interfaceFilters];
|
|
47
81
|
if (identifierFilters.length > 0) {
|
|
48
|
-
return
|
|
82
|
+
return buildIdentifierFilters(params);
|
|
49
83
|
}
|
|
50
84
|
if (params.includeCreatedEventBlob) {
|
|
51
|
-
return
|
|
52
|
-
{
|
|
53
|
-
identifierFilter: {
|
|
54
|
-
WildcardFilter: {
|
|
55
|
-
value: {
|
|
56
|
-
includeCreatedEventBlob: true,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
];
|
|
85
|
+
return wildcardFilter(true);
|
|
62
86
|
}
|
|
63
87
|
return [];
|
|
64
88
|
};
|
|
65
89
|
return {
|
|
66
|
-
verbose
|
|
90
|
+
verbose,
|
|
67
91
|
filtersByParty: Object.fromEntries(params.parties.map((p) => [
|
|
68
92
|
p,
|
|
69
93
|
{
|
|
@@ -78,7 +102,7 @@ function buildEventFormat(params) {
|
|
|
78
102
|
*
|
|
79
103
|
* @param params - Event format parameters and an optional `transactionShape`
|
|
80
104
|
* @returns A transaction format using `TRANSACTION_SHAPE_LEDGER_EFFECTS` unless a shape is given
|
|
81
|
-
* @throws Error if
|
|
105
|
+
* @throws Error if neither a non-empty `parties` list nor `anyParty: true` is given, or if both are
|
|
82
106
|
*/
|
|
83
107
|
function buildTransactionFormat(params) {
|
|
84
108
|
return {
|
|
@@ -88,27 +112,29 @@ function buildTransactionFormat(params) {
|
|
|
88
112
|
}
|
|
89
113
|
/**
|
|
90
114
|
* Builds the update format that `subscribeToUpdates` sends, so it can also be passed as the `updateFormat` of
|
|
91
|
-
* `getUpdateByOffset
|
|
115
|
+
* `getUpdateByOffset`, `getUpdatesPage`, `getRawUpdatesPage` and `subscribeToRawUpdates`. Reassignments reuse the same
|
|
116
|
+
* filters. Topology events cover the same parties: the listed ones, or, with `anyParty`, every party (an empty
|
|
117
|
+
* participant-authorization format, which the Ledger API reads as all parties).
|
|
92
118
|
*
|
|
93
119
|
* @param params - Transaction format parameters and the optional reassignment and topology switches
|
|
94
120
|
* @returns An update format with transactions, reassignments (unless disabled) and topology events (when enabled)
|
|
95
|
-
* @throws Error if
|
|
121
|
+
* @throws Error if neither a non-empty `parties` list nor `anyParty: true` is given, or if both are
|
|
96
122
|
*/
|
|
97
123
|
function buildUpdateFormat(params) {
|
|
98
124
|
const includeTransactions = buildTransactionFormat(params);
|
|
125
|
+
const { eventFormat } = includeTransactions;
|
|
99
126
|
return {
|
|
100
127
|
includeTransactions,
|
|
101
128
|
...(params.includeReassignments !== false && {
|
|
102
129
|
includeReassignments: {
|
|
103
|
-
filtersByParty:
|
|
104
|
-
|
|
130
|
+
filtersByParty: eventFormat.filtersByParty,
|
|
131
|
+
...(eventFormat.filtersForAnyParty !== undefined && { filtersForAnyParty: eventFormat.filtersForAnyParty }),
|
|
132
|
+
verbose: eventFormat.verbose ?? false,
|
|
105
133
|
},
|
|
106
134
|
}),
|
|
107
135
|
...(params.includeTopologyEvents === true && {
|
|
108
136
|
includeTopologyEvents: {
|
|
109
|
-
includeParticipantAuthorizationEvents: {
|
|
110
|
-
parties: params.parties,
|
|
111
|
-
},
|
|
137
|
+
includeParticipantAuthorizationEvents: params.anyParty === true ? {} : { parties: [...params.parties] },
|
|
112
138
|
},
|
|
113
139
|
}),
|
|
114
140
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-format-builder.js","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/event-format-builder.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"event-format-builder.js","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/event-format-builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;AA2GH,SAAS,sBAAsB,CAAC,MAA0B;IACxD,MAAM,uBAAuB,GAAG,MAAM,CAAC,uBAAuB,IAAI,KAAK,CAAC;IACxE,MAAM,eAAe,GAAqB,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,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AC;IAC3D,MAAM,EAAE,WAAW,EAAE,GAAG,mBAAmB,CAAC;IAE5C,OAAO;QACL,mBAAmB;QACnB,GAAG,CAAC,MAAM,CAAC,oBAAoB,KAAK,KAAK,IAAI;YAC3C,oBAAoB,EAAE;gBACpB,cAAc,EAAE,WAAW,CAAC,cAAc;gBAC1C,GAAG,CAAC,WAAW,CAAC,kBAAkB,KAAK,SAAS,IAAI,EAAE,kBAAkB,EAAE,WAAW,CAAC,kBAAkB,EAAE,CAAC;gBAC3G,OAAO,EAAE,WAAW,CAAC,OAAO,IAAI,KAAK;aACtC;SACF,CAAC;QACF,GAAG,CAAC,MAAM,CAAC,qBAAqB,KAAK,IAAI,IAAI;YAC3C,qBAAqB,EAAE;gBACrB,qCAAqC,EAAE,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE;aACxG;SACF,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whose events a ledger read returns: the events of a list of parties, or the events of every party the participant
|
|
3
|
+
* hosts.
|
|
4
|
+
*
|
|
5
|
+
* A party list is a filter. A party the list misses, such as one allocated after the list was written, is read as if it
|
|
6
|
+
* did not exist, without any error. `{ anyParty: true }` sends `filtersForAnyParty` instead, which covers every party
|
|
7
|
+
* on the participant, including parties that appear later. It needs the user's `CanReadAsAnyParty` right; check it with
|
|
8
|
+
* `assertCanReadAsAnyParty` before a long read.
|
|
9
|
+
*
|
|
10
|
+
* The two forms exclude each other: the types reject an object with both keys, and the reads reject one at run time.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
/** Read as the listed parties (`filtersByParty`). */
|
|
14
|
+
export interface PartiesScope {
|
|
15
|
+
/** Parties to read as. */
|
|
16
|
+
readonly parties: string[];
|
|
17
|
+
readonly anyParty?: never;
|
|
18
|
+
}
|
|
19
|
+
/** Read as every party the participant hosts (`filtersForAnyParty`). Needs the `CanReadAsAnyParty` right. */
|
|
20
|
+
export interface AnyPartyScope {
|
|
21
|
+
readonly anyParty: true;
|
|
22
|
+
readonly parties?: never;
|
|
23
|
+
}
|
|
24
|
+
/** Whose events a format selects: `{ parties }` or `{ anyParty: true }`, never both. */
|
|
25
|
+
export type PartyScope = AnyPartyScope | PartiesScope;
|
|
26
|
+
/** True when the scope reads as every party. */
|
|
27
|
+
export declare function isAnyPartyScope(scope: PartyScope): scope is AnyPartyScope;
|
|
28
|
+
/**
|
|
29
|
+
* A schema that rejects `anyParty` with any value other than `true`, and `anyParty` together with the party-list key
|
|
30
|
+
* the operation uses (`parties` or `readAs`), with a message naming both. Pipe it into the operation's
|
|
31
|
+
* `z.discriminatedUnion('anyParty', [partyListSchema, anyPartySchema])`: it runs first, so the caller sees this message
|
|
32
|
+
* rather than a discriminator mismatch, and the discriminated union then reports any other problem at its field,
|
|
33
|
+
* exactly as the party-list schema alone does.
|
|
34
|
+
*/
|
|
35
|
+
export declare function partyScopeGuard(listKey: 'parties' | 'readAs'): z.ZodType<unknown>;
|
|
36
|
+
//# sourceMappingURL=party-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"party-scope.d.ts","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/party-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;CAC3B;AAED,6GAA6G;AAC7G,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;CAC1B;AAED,wFAAwF;AACxF,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,YAAY,CAAC;AAEtD,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,IAAI,aAAa,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAajF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAnyPartyScope = isAnyPartyScope;
|
|
4
|
+
exports.partyScopeGuard = partyScopeGuard;
|
|
5
|
+
/**
|
|
6
|
+
* Whose events a ledger read returns: the events of a list of parties, or the events of every party the participant
|
|
7
|
+
* hosts.
|
|
8
|
+
*
|
|
9
|
+
* A party list is a filter. A party the list misses, such as one allocated after the list was written, is read as if it
|
|
10
|
+
* did not exist, without any error. `{ anyParty: true }` sends `filtersForAnyParty` instead, which covers every party
|
|
11
|
+
* on the participant, including parties that appear later. It needs the user's `CanReadAsAnyParty` right; check it with
|
|
12
|
+
* `assertCanReadAsAnyParty` before a long read.
|
|
13
|
+
*
|
|
14
|
+
* The two forms exclude each other: the types reject an object with both keys, and the reads reject one at run time.
|
|
15
|
+
*/
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
const type_guards_1 = require("../../../../../core/utils/type-guards");
|
|
18
|
+
/** True when the scope reads as every party. */
|
|
19
|
+
function isAnyPartyScope(scope) {
|
|
20
|
+
return scope.anyParty === true;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A schema that rejects `anyParty` with any value other than `true`, and `anyParty` together with the party-list key
|
|
24
|
+
* the operation uses (`parties` or `readAs`), with a message naming both. Pipe it into the operation's
|
|
25
|
+
* `z.discriminatedUnion('anyParty', [partyListSchema, anyPartySchema])`: it runs first, so the caller sees this message
|
|
26
|
+
* rather than a discriminator mismatch, and the discriminated union then reports any other problem at its field,
|
|
27
|
+
* exactly as the party-list schema alone does.
|
|
28
|
+
*/
|
|
29
|
+
function partyScopeGuard(listKey) {
|
|
30
|
+
return zod_1.z.unknown().superRefine((value, ctx) => {
|
|
31
|
+
if (!(0, type_guards_1.isRecord)(value) || value['anyParty'] === undefined)
|
|
32
|
+
return;
|
|
33
|
+
if (value['anyParty'] !== true) {
|
|
34
|
+
ctx.addIssue({ code: 'custom', path: ['anyParty'], message: 'anyParty must be true when it is given' });
|
|
35
|
+
}
|
|
36
|
+
else if (value[listKey] !== undefined) {
|
|
37
|
+
ctx.addIssue({
|
|
38
|
+
code: 'custom',
|
|
39
|
+
path: ['anyParty'],
|
|
40
|
+
message: `pass either anyParty: true or ${listKey}, not both`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=party-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"party-scope.js","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/party-scope.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;GAUG;AACH,6BAAwB;AACxB,uEAAiE;AAkBjE,gDAAgD;AAChD,yBAAgC,KAAiB;IAC/C,OAAO,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,yBAAgC,OAA6B;IAC3D,OAAO,OAAC,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC5C,IAAI,CAAC,IAAA,sBAAQ,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,SAAS;YAAE,OAAO;QAChE,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC;YAC/B,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,wCAAwC,EAAE,CAAC,CAAC;QAC1G,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;YACxC,GAAG,CAAC,QAAQ,CAAC;gBACX,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,UAAU,CAAC;gBAClB,OAAO,EAAE,iCAAiC,OAAO,YAAY;aAC9D,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw WebSocket reader behind `subscribeToRawUpdates` and `subscribeToRawCompletions`.
|
|
3
|
+
*
|
|
4
|
+
* It hands each frame to the consumer exactly as the participant sent it (the text, and its `JSON.parse` value checked
|
|
5
|
+
* to keep every number and key), one at a time and in order, and keeps the offset of the last frame the consumer has
|
|
6
|
+
* handled so that a new subscription can resume from it. No Zod schema touches a frame.
|
|
7
|
+
*/
|
|
8
|
+
import { type BaseClient } from '../../../../../core/BaseClient';
|
|
9
|
+
import { ApiError, type ErrorContext } from '../../../../../core/errors';
|
|
10
|
+
import { type WebSocketOptions } from '../../../../../core/ws/WebSocketClient';
|
|
11
|
+
/**
|
|
12
|
+
* Most received frames that wait for the consumer before the socket stops reading. Past it the participant's sends back
|
|
13
|
+
* up behind TCP flow control instead of collecting in memory; reading resumes once half have been handled.
|
|
14
|
+
*/
|
|
15
|
+
export declare const RAW_STREAM_HIGH_WATER_MARK = 256;
|
|
16
|
+
/** A frame kind the SDK knows, or any other kind a newer participant sends. */
|
|
17
|
+
export type RawFrameKind<Known extends string> = Known | (string & Record<never, never>);
|
|
18
|
+
/** One WebSocket frame exactly as the participant sent it. */
|
|
19
|
+
export interface RawFrame<Known extends string = string> {
|
|
20
|
+
/** The frame as received (its UTF-8 text). Store this to keep the exact bytes. */
|
|
21
|
+
readonly text: string;
|
|
22
|
+
/**
|
|
23
|
+
* `JSON.parse(text)`, unnormalized. Every number in it equals the number written in `text`, and no key was dropped; a
|
|
24
|
+
* frame that would lose either ends the stream with a `RawStreamError` instead of being delivered.
|
|
25
|
+
*/
|
|
26
|
+
readonly json: unknown;
|
|
27
|
+
/** The frame's variant, e.g. `Transaction` or `OffsetCheckpoint`; a kind this SDK does not know is still delivered. */
|
|
28
|
+
readonly kind: RawFrameKind<Known>;
|
|
29
|
+
/** The offset the frame carries, if any (every known kind except `Empty` carries one). */
|
|
30
|
+
readonly offset: number | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Why a raw stream ended without an error. */
|
|
33
|
+
export type RawStreamEndReason =
|
|
34
|
+
/** The participant closed the stream normally (code 1000): a bounded range was read to its end. */
|
|
35
|
+
'completed'
|
|
36
|
+
/** The access token was about to expire; the stream was closed (code 4000 unless the hook chose another). */
|
|
37
|
+
| 'token-refresh'
|
|
38
|
+
/** `close()` was called. */
|
|
39
|
+
| 'closed';
|
|
40
|
+
/** How a raw stream ended. */
|
|
41
|
+
export interface RawStreamEnd {
|
|
42
|
+
readonly reason: RawStreamEndReason;
|
|
43
|
+
/** Offset of the last frame the consumer handled, or the `beginExclusive` passed in. Resume from it. */
|
|
44
|
+
readonly lastOffset: number;
|
|
45
|
+
/** The WebSocket close code, when the socket closed rather than `close()` being called. */
|
|
46
|
+
readonly closeCode: number | undefined;
|
|
47
|
+
}
|
|
48
|
+
/** A running raw stream. */
|
|
49
|
+
export interface RawStreamSubscription {
|
|
50
|
+
/**
|
|
51
|
+
* Offset of the last frame (an update, a completion or an offset checkpoint) whose `onFrame` has resolved; the
|
|
52
|
+
* `beginExclusive` passed in until then. It never goes back. Pass it as `beginExclusive` to resume after any end or
|
|
53
|
+
* failure: every frame after it is delivered again, none before it.
|
|
54
|
+
*/
|
|
55
|
+
readonly lastOffset: number;
|
|
56
|
+
/**
|
|
57
|
+
* Settles once the stream has ended and no `onFrame` call is still running: resolves with how it ended, or rejects
|
|
58
|
+
* with the first failure (a `RawStreamError`, the error a `onFrame` call threw, or a connection error).
|
|
59
|
+
*/
|
|
60
|
+
readonly done: Promise<RawStreamEnd>;
|
|
61
|
+
/** Stops reading and closes the socket; frames not yet handed to `onFrame` are dropped. Closing twice does nothing. */
|
|
62
|
+
readonly close: () => void;
|
|
63
|
+
}
|
|
64
|
+
/** What went wrong in a raw stream. */
|
|
65
|
+
export type RawStreamErrorReason =
|
|
66
|
+
/** The participant sent an error frame (`ledgerCode` holds its code, e.g. `PARTICIPANT_PRUNED_DATA_ACCESSED`). */
|
|
67
|
+
'error-frame'
|
|
68
|
+
/** A frame that is neither a data frame of this stream nor an error frame, or a data frame without its offset. */
|
|
69
|
+
| 'unexpected-frame'
|
|
70
|
+
/** `JSON.parse` would have changed a number or dropped a repeated key (see `LossyJsonError`). */
|
|
71
|
+
| 'lossy-json'
|
|
72
|
+
/** A frame's offset did not follow the previous frame's. */
|
|
73
|
+
| 'out-of-order'
|
|
74
|
+
/** The socket closed with a code other than 1000 before the stream ended. */
|
|
75
|
+
| 'abnormal-close';
|
|
76
|
+
/** A raw stream ended because of the ledger or the connection rather than the consumer. */
|
|
77
|
+
export declare class RawStreamError extends ApiError {
|
|
78
|
+
/** What went wrong. */
|
|
79
|
+
readonly reason: RawStreamErrorReason;
|
|
80
|
+
/** The Canton error code of an error frame. */
|
|
81
|
+
readonly ledgerCode?: string | undefined;
|
|
82
|
+
/** The WebSocket close code of an abnormal close. */
|
|
83
|
+
readonly closeCode?: number | undefined;
|
|
84
|
+
readonly name: string;
|
|
85
|
+
constructor(message: string,
|
|
86
|
+
/** What went wrong. */
|
|
87
|
+
reason: RawStreamErrorReason,
|
|
88
|
+
/** The Canton error code of an error frame. */
|
|
89
|
+
ledgerCode?: string | undefined,
|
|
90
|
+
/** The WebSocket close code of an abnormal close. */
|
|
91
|
+
closeCode?: number | undefined, context?: ErrorContext);
|
|
92
|
+
}
|
|
93
|
+
/** What a raw stream reads, and how its frames look. */
|
|
94
|
+
export interface RawStreamSpec<Known extends string> {
|
|
95
|
+
readonly client: BaseClient;
|
|
96
|
+
/** Name used in error messages, e.g. `updates`. */
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly path: string;
|
|
99
|
+
/** The request message, sent as given. */
|
|
100
|
+
readonly request: Record<string, unknown>;
|
|
101
|
+
readonly beginExclusive: number;
|
|
102
|
+
/** The top-level key of a data frame: `update` or `completionResponse`. */
|
|
103
|
+
readonly dataKey: string;
|
|
104
|
+
/** Kinds that must carry `value.offset`; a frame of one of them without it ends the stream. */
|
|
105
|
+
readonly offsetKinds: readonly string[];
|
|
106
|
+
readonly onFrame: (frame: RawFrame<Known>) => void | Promise<void>;
|
|
107
|
+
readonly idleTimeoutMs?: number | undefined;
|
|
108
|
+
readonly onTokenExpiring?: WebSocketOptions['onTokenExpiring'] | undefined;
|
|
109
|
+
readonly onTokenRefreshNeeded?: WebSocketOptions['onTokenRefreshNeeded'] | undefined;
|
|
110
|
+
}
|
|
111
|
+
/** Opens a raw stream; see {@link RawStreamSubscription}. */
|
|
112
|
+
export declare function openRawFrameStream<Known extends string>(spec: RawStreamSpec<Known>): RawStreamSubscription;
|
|
113
|
+
//# sourceMappingURL=raw-frame-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-frame-stream.d.ts","sourceRoot":"","sources":["../../../../../../../src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGzE,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,wCAAwC,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAQ9C,+EAA+E;AAC/E,MAAM,MAAM,YAAY,C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