Skip to content

Instantly share code, notes, and snippets.

@dannycoates
Created October 24, 2013 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannycoates/7145488 to your computer and use it in GitHub Desktop.
Save dannycoates/7145488 to your computer and use it in GitHub Desktop.
abstract db interface
/*/
# Notes
All endpoints that use HAWK require tokens and the token must be read from the
db to validate the request. Ideally all data required for an endpoint to do it's
job can be read in the same db call.
Different db implementations will have different data layouts. For example, SQL
may use a join to get the keys for a keyFetchToken, while Cassandra will store
a copy of the keys in the keyFetchToken record. In the denormalized case some
types have extra data that aren't used by that type directly but are needed to
create derived types. In the SQL with joins model these fields are extraneous.
Such fields should not be used "above" the db abstraction and should be
considered undefined so that implementations that don't need them can safely
exclude them from being read from the db.
The various token lists also have different implementations. In SQL an index on
uid makes them automatic. Cassandra manages them manually. These should be
"hidden" as much as possible and handled below this abstraction. The only
current list accessed through the api is /account/devices. Things like this
should make a separate db read to retrieve the list instead of expecting it to
exist on the type.
/*/
module.exports = function () {
function DB() {
}
// CREATE
DB.prototype.createSessionToken = function (authToken) {
}
DB.prototype.createKeyFetchToken = function (authToken) {
}
DB.prototype.createAccountResetToken = function (token /* authToken|forgotPasswordToken */) {
}
DB.prototype.createAuthToken = function (srpToken) {
}
DB.prototype.createSrpToken = function (emailRecord) {
}
DB.prototype.createForgotPasswordToken = function (emailRecord) {
}
// READ
DB.prototype.accountExists = function (email) {
}
DB.prototype.accountDevices = function (uid) {
}
DB.prototype.sessionToken = function (id) {
}
DB.prototype.keyFetchToken = function (id) {
}
DB.prototype.accountResetToken = function (id) {
}
DB.prototype.authToken = function (id) {
}
DB.prototype.srpToken = function (id) {
}
DB.prototype.forgotPasswordToken = function (id) {
}
DB.prototype.emailRecord = function (email) {
}
DB.prototype.account = function (uid) {
}
// UPDATE
DB.prototype.udateForgotPasswordToken = function (forgotPasswordToken) {
}
// DELETE
DB.prototype.deleteSessionToken = function (sessionToken) {
}
DB.prototype.deleteKeyFetchToken = function (keyFetchToken) {
}
DB.prototype.deleteAccountResetToken = function (accountResetToken) {
}
DB.prototype.deleteAuthToken = function (authToken) {
}
DB.prototype.deleteSrpToken = function (srpToken) {
}
DB.prototype.deleteForgotPasswordToken = function (forgotPasswordToken) {
}
// BATCH
DB.prototype.createAccount = function (data) {
// both Account and EmailRecord
}
DB.prototype.deleteAccount = function (authToken) {
}
DB.prototype.resetAccount = function (accountResetToken, data) {
}
DB.prototype.authFinish = function (srpToken, authToken) {
}
DB.prototype.createSession = function (sessionData, keyData) {
}
DB.prototype.verifyEmail = function (account) {
}
DB.prototype.createPasswordChange = function (keyFetchData, accountResetData) {
}
DB.prototype.forgotPasswordVerified = function (forgotPasswordToken, accountResetData) {
}
return DB
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment