Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

feat(sortKey): add sortKey to contract response #53

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
ignores: [(message) => message.includes('[skip ci]')],
rules: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - it was preventing good commit messages that @djwhitt has pioneered

'header-max-length': [0, 'always'],
'body-max-line-length': [0, 'always'],
},
};
7 changes: 5 additions & 2 deletions src/api/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { ParsedUrlQuery } from 'querystring';

// cache duplicate requests on the same instance within a short period of time
const requestMap: Map<string, Promise<any> | undefined> = new Map();

Check warning on line 24 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type

// Convenience class for read through caching
class ContractStateCacheKey {
Expand Down Expand Up @@ -74,7 +74,7 @@
constructor(
public readonly contractTxId: string,
public readonly functionName: string,
public readonly input: any,

Check warning on line 77 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
public readonly warp: Warp,
public readonly evaluationOptions: Partial<EvaluationOptions>,
public readonly logger?: winston.Logger,
Expand All @@ -96,7 +96,7 @@
const contractReadInteractionCache: ReadThroughPromiseCache<
ContractReadInteractionCacheKey,
{
result: any;

Check warning on line 99 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
evaluationOptions: Partial<EvaluationOptions>;
}
> = new ReadThroughPromiseCache({
Expand Down Expand Up @@ -144,9 +144,10 @@
contractTxId,
cacheKey: cacheKey.toString(),
});
const { cachedValue } = await inFlightRequest;
const { cachedValue, sortKey } = await inFlightRequest;
return {
...cachedValue,
sortKey,
evaluationOptions,
};
}
Expand Down Expand Up @@ -182,14 +183,16 @@
});

// 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,
};
}
Expand Down Expand Up @@ -221,8 +224,8 @@
return new NotFoundError(error.message);
} else if (
(error instanceof Error &&
(error as any).type &&

Check warning on line 227 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
['TX_NOT_FOUND', 'TX_INVALID'].includes((error as any).type)) ||

Check warning on line 228 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
(typeof error === 'string' && (error as string).includes('TX_INVALID'))
) {
return new NotFoundError(`Contract not found. ${error}`);
Expand Down Expand Up @@ -265,7 +268,7 @@
export async function readThroughToContractReadInteraction(
cacheKey: ContractReadInteractionCacheKey,
): Promise<{
result: any;

Check warning on line 271 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
evaluationOptions: Partial<EvaluationOptions>;
}> {
const { contractTxId, evaluationOptions, warp, logger, functionName, input } =
Expand Down Expand Up @@ -350,7 +353,7 @@
functionName: string;
input: ParsedUrlQuery;
}): Promise<{
result: any;

Check warning on line 356 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
evaluationOptions: Partial<EvaluationOptions>;
}> {
try {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
logger.debug('Fetching contract state', {
contractTxId,
});
const { state, evaluationOptions } = await getContractState({
const { state, evaluationOptions, sortKey } = await getContractState({
contractTxId,
warp,
logger,
});
ctx.body = {
contractTxId,
state,
sortKey,
evaluationOptions,
};

Expand Down Expand Up @@ -201,8 +202,8 @@

const associatedRecords = Object.entries(records).reduce(
(
filteredRecords: { [x: string]: any },

Check warning on line 205 in src/routes/contract.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
[record, recordObj]: [string, any],

Check warning on line 206 in src/routes/contract.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
) => {
if (
!filteredContractTxIdsArray.length ||
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@

// Warp types

export type EvaluatedContractState = EvalStateResult<any> & {

Check warning on line 71 in src/types.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
evaluationOptions?: Partial<EvaluationOptions>;
evaluationOptions: Partial<EvaluationOptions>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we intend to lose the optionality of this in the interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - we will always return it

sortKey: string;
};

export type EvaluatedReadInteraction = {
Expand Down