Skip to content
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

pagination: consider re-adding guidance on pagination token #189

Open
toumorokoshi opened this issue May 16, 2024 · 0 comments
Open

pagination: consider re-adding guidance on pagination token #189

toumorokoshi opened this issue May 16, 2024 · 0 comments

Comments

@toumorokoshi
Copy link
Member

toumorokoshi commented May 16, 2024

reference: #168 (comment)_

removed content, to consider re-adding:

## Implementation

Page tokens **should** be versioned independently of the public API, so that
page tokens can be used with any version of the service.

The simplest form of a page token only requires an offset. However, offsets
pose challenges when a distributed database is introduced, so a more robust
page token needs to store the information needed to find a "logical" position
in the database. The simplest way to do this is to include relevant data from
the last result returned. Primarily, this means the resource ID, but also
includes any other fields from the resource used to sort the results (for the
event where the resource is changed or deleted).

This information is from the resource itself, and therefore might be sensitive.
Sensitive data **must** be encrypted before being used in a page token.
Therefore, the token also includes the date it was created, to allow for the
potential need to rotate the encryption key.

This yields the following interface, which **may** be base64 encoded and used
as a page token:

\```typescript
interface PageTokenSecrets {
  // The ID of the most recent resource returned.
  lastId: string;

  // Any index data needed, generally 1:1 with the fields used for ordering.
  indexData: Buffer[];

  // When this token was minted.
  createTime: Date;
}
\```

**Note:** This section does not preclude alternative page token implementations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant