From 1a5e2b120d7afa432a86d4a0fb2577968f344b27 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Fri, 10 Nov 2023 11:46:00 -0700 Subject: [PATCH] feat(sortKey): add sortKey to contract payload This allows those evaluating contract state using warp to use this service to bootstrap state from our cache --- commitlint.config.js | 4 ++++ src/api/warp.ts | 7 +++++-- src/routes/contract.ts | 3 ++- src/types.ts | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index fd6f7d4..8a81ac7 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -19,4 +19,8 @@ module.exports = { extends: ['@commitlint/config-conventional'], ignores: [(message) => message.includes('[skip ci]')], + rules: { + 'header-max-length': [0, 'always'], + 'body-max-line-length': [0, 'always'], + }, }; diff --git a/src/api/warp.ts b/src/api/warp.ts index 0cf743e..3682625 100644 --- a/src/api/warp.ts +++ b/src/api/warp.ts @@ -144,9 +144,10 @@ async function readThroughToContractState( contractTxId, cacheKey: cacheKey.toString(), }); - const { cachedValue } = await inFlightRequest; + const { cachedValue, sortKey } = await inFlightRequest; return { ...cachedValue, + sortKey, evaluationOptions, }; } @@ -182,14 +183,16 @@ async function readThroughToContractState( }); // await the response - const { cachedValue } = await requestMap.get(cacheId); + const { cachedValue, sortKey } = await requestMap.get(cacheId); logger?.debug('Successfully evaluated contract state.', { contractTxId, cacheKey: cacheKey.toString(), + sortKey, }); return { ...cachedValue, + sortKey, evaluationOptions, }; } diff --git a/src/routes/contract.ts b/src/routes/contract.ts index 914561d..0609379 100644 --- a/src/routes/contract.ts +++ b/src/routes/contract.ts @@ -15,7 +15,7 @@ export async function contractHandler(ctx: KoaContext, next: Next) { logger.debug('Fetching contract state', { contractTxId, }); - const { state, evaluationOptions } = await getContractState({ + const { state, evaluationOptions, sortKey } = await getContractState({ contractTxId, warp, logger, @@ -23,6 +23,7 @@ export async function contractHandler(ctx: KoaContext, next: Next) { ctx.body = { contractTxId, state, + sortKey, evaluationOptions, }; diff --git a/src/types.ts b/src/types.ts index 6a196eb..329d957 100644 --- a/src/types.ts +++ b/src/types.ts @@ -69,7 +69,8 @@ export type ContractReservedResponse = ContractBaseResponse & { // Warp types export type EvaluatedContractState = EvalStateResult & { - evaluationOptions?: Partial; + evaluationOptions: Partial; + sortKey: string; }; export type EvaluatedReadInteraction = {