-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ant): add priority
as an attribute on ANTs, utility function for sorting algo
#376
Conversation
0737d42
to
db31a3b
Compare
3e5c21d
to
66c5211
Compare
priority
as an attribute on ANTspriority
as an attribute on ANTs, utility function for sorting algo
ANTs can optionally provide a priority order of their records. This is how ar-io gateways will enforce undername limits. If no priority order is provided, records will be sorted lexigraphically
Update unit tests to be closer to their respective implementations
8739bf8
to
3ad1d07
Compare
}); | ||
export type AoANTRecord = z.infer<typeof AntRecordSchema>; | ||
export type ANTRecords = Record<string, AoANTRecord>; | ||
export type SortedANTRecord = AoANTRecord & { index: number }; | ||
export type SortedANTRecords = Record<string, SortedANTRecord>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It's nice when the key type is a type alias that describes the domain of the key string.
🎉 This PR is included in version 3.5.0-alpha.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
describe('sortANTRecordsByPriority', () => { | ||
it('should sort records by priority and then lexicographically', () => { | ||
const records = { | ||
undername1: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be insightful to have undername11 with priority 1 to ensure the lexicographical sort is working as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And perhaps undername01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in #385
// if both records have a priority, sort by priority and fallback to lexicographic sorting | ||
if (aRecord.priority !== undefined && bRecord.priority !== undefined) { | ||
if (aRecord.priority === bRecord.priority) { | ||
return a.localeCompare(b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: localeCompare's behavior can be overridden by the host platform's ENV vars like LC_ALL, LC_COLLATE, or LANG. Could lead to inconsistent results across user platforms.
}); | ||
}); | ||
|
||
it('should always return @ as the first record, regardless of priority', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seem to be missing tests for mixed priority and no priority
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in #385
🎉 This PR is included in version 3.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
ANTs can optionally provide a priority order of their records. This is how ar-io gateways will enforce undername limits. If no priority order is provided, records will be sorted lexicographically.
This PR updates the type for ANRecords, and adds a utility to provide the proper sorting. We could extend this in the future to allow ar-io-nodes to choose their default sort behavior.
References: