@fairmint/canton-node-sdk
Version:
Canton Node SDK
59 lines • 2.12 kB
JavaScript
;
/**
* Shared utility for building eventFormat configuration used across multiple Ledger JSON API operations. This module
* provides a consistent way to construct the complex eventFormat structure from simple parameters.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildEventFormat = buildEventFormat;
/**
* Builds the eventFormat object structure used in various Ledger JSON API operations. This centralizes the logic for
* creating filtersByParty configurations from simple parameters.
*
* @param params - Configuration parameters for building the event format
* @returns An eventFormat object ready to be used in API requests
* @throws Error if no parties are provided
*/
function buildEventFormat(params) {
if (params.parties.length === 0) {
throw new Error('At least one party is required for event format filters');
}
// Build the cumulative filter array
const buildCumulative = () => {
if (params.templateIds && params.templateIds.length > 0) {
return params.templateIds.map((templateId) => ({
identifierFilter: {
TemplateFilter: {
value: {
templateId,
includeCreatedEventBlob: params.includeCreatedEventBlob ?? false,
},
},
},
}));
}
if (params.includeCreatedEventBlob) {
return [
{
identifierFilter: {
WildcardFilter: {
value: {
includeCreatedEventBlob: true,
},
},
},
},
];
}
return [];
};
return {
verbose: false,
filtersByParty: Object.fromEntries(params.parties.map((p) => [
p,
{
cumulative: buildCumulative(),
},
])),
};
}
//# sourceMappingURL=event-format-builder.js.map