- uuid: {
- type: DataTypes.UUID,
- defaultValue: DataTypes.UUIDV4,
- allowNull: false,
- validate: {
- isUUID: 4
- }
- },
- name: {
- type: DataTypes.STRING,
- allowNull: false,
- validate: {
- nameValid: value => {
- const res = isUserUsernameValid(value)
- if (res === false) throw new Error('Name is not valid.')
- }
- }
- },
- url: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
- allowNull: false,
- validate: {
- urlValid: value => {
- const res = isAccountUrlValid(value)
- if (res === false) throw new Error('URL is not valid.')
- }
- }
- },
- publicKey: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY.max),
- allowNull: true,
- validate: {
- publicKeyValid: value => {
- const res = isAccountPublicKeyValid(value)
- if (res === false) throw new Error('Public key is not valid.')
- }
- }
- },
- privateKey: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max),
- allowNull: true,
- validate: {
- privateKeyValid: value => {
- const res = isAccountPrivateKeyValid(value)
- if (res === false) throw new Error('Private key is not valid.')
- }
- }
- },
- followersCount: {
- type: DataTypes.INTEGER,
- allowNull: false,
- validate: {
- followersCountValid: value => {
- const res = isAccountFollowersCountValid(value)
- if (res === false) throw new Error('Followers count is not valid.')
- }
- }
- },
- followingCount: {
- type: DataTypes.INTEGER,
- allowNull: false,
- validate: {
- followingCountValid: value => {
- const res = isAccountFollowingCountValid(value)
- if (res === false) throw new Error('Following count is not valid.')
- }
- }
- },
- inboxUrl: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
- allowNull: false,
- validate: {
- inboxUrlValid: value => {
- const res = isAccountInboxValid(value)
- if (res === false) throw new Error('Inbox URL is not valid.')
- }
- }
- },
- outboxUrl: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
- allowNull: false,
- validate: {
- outboxUrlValid: value => {
- const res = isAccountOutboxValid(value)
- if (res === false) throw new Error('Outbox URL is not valid.')
- }
- }
- },
- sharedInboxUrl: {
- type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
- allowNull: false,
- validate: {
- sharedInboxUrlValid: value => {
- const res = isAccountSharedInboxValid(value)
- if (res === false) throw new Error('Shared inbox URL is not valid.')
- }
+ model: ActorModel, // Default scope includes avatar and server
+ required: true
+ }
+ ]
+}))
+@Scopes(() => ({
+ [ ScopeNames.SUMMARY ]: (options: SummaryOptions = {}) => {
+ const whereActor = options.whereActor || undefined
+
+ const serverInclude: IncludeOptions = {
+ attributes: [ 'host' ],
+ model: ServerModel.unscoped(),
+ required: false
+ }
+
+ const query: FindOptions = {
+ attributes: [ 'id', 'name' ],
+ include: [
+ {
+ attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
+ model: ActorModel.unscoped(),
+ required: true,
+ where: whereActor,
+ include: [
+ serverInclude,
+
+ {
+ model: AvatarModel.unscoped(),
+ required: false
+ }
+ ]