0.1.6Updated a month ago
declare namespace Entity {
  namespace Key {
    interface Options {
      /**
       * What is the maximum length a key value could be?
       * 
       * A *key* is used to identify ledger data based on a user. Usually the `msisdn`.
       * 
       * This is used when creating the ledger tables to improve performance.
       * 
       * **Default**: `11` if user-based, otherwise `16`
       */
      max_length?: number

      validator?: KeyValidator

      formatter?: KeyFormatter
    }
  }
}

type KeyValidation = KeyValidationSuccess | KeyValidationFailure

interface ValidationKeyResponseSuccess extends KeyValidationSuccess {
  key: string
}

interface ValidationKeyResponseFailure extends KeyValidationFailure {
  key: string
}

type ValidateKeyResponse = ValidationKeyResponseSuccess | ValidationKeyResponseFailure

type KeyValidator = (key: string) => KeyValidation | boolean

type KeyFormatter = (key: string) => string | null

interface KeyValidationSuccess {
  valid: true
  reason: null
}

interface KeyValidationFailure {
  valid: false
  reason: string
}