mattermost-mobile-upstream/types/database/database.ts
Pablo Vélez 4d842026f6
Some checks failed
ci / lint-typecheck (push) Has been cancelled
ci / detox-lint-typecheck (push) Has been cancelled
ci / test (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Mm 70564 channel labels use in channel creation (#10146)
* MM-70516 - Add ability to edit channel attribute values from Channel Info

* Add API methods for patching property fields and setting channel attribute requirements

* Update channel attribute clearing behavior for required and non-required fields

* MM-70564 - use channel attributes on channel creation

* Fix undefined propertyValues and ternary formatting in channel attributes

* Fix spelling of "colour" to "color" in attribute chip tests and related comments

* Add visibility checks for channel attribute labels in tests

* Fix data-integrity, permission, and accessibility issues in channel attributes: scoped pruning, atomic writes, race serialization, required clear/stale-option guards

* Fix handling of null values in apiGetChannelAttributeValue and update test assertions for channel attributes

* Improve channel attribute editor sizing for long labels, keep Save visible, and prevent keyboard overlap on Android

* Address CodeRabbit feedback for nullable values, bottom-sheet state, async validation, and reliable E2E cleanup

* lock-safe field fetch, create-time gate recheck, scoped value pruning, and tappable header chips

* Address CodeRabbit feedback: drop queued attribute saves on channel switch and use page object selectors in E2E

* Respect the ChannelAttributesRequired flag on channel creation and enable it for channel attribute E2E

* Skip required channel attribute E2E tests and stop enabling ChannelAttributesRequired on the shared server until  they move to SITE_3

* Fix clearing channel attributes on iOS by sending an empty value instead of null, and stop E2E suites from turning  off the ChannelAttributes flag mid-run

* Refactor getEmptyPropertyValue to accept string type for fieldType parameter

* E2E: give channel attribute test fields a suite-unique suffix

Pool shards may only create optional property fields named <name>_<6 hex>; fixed names were blocked by the pool guard.

* E2E: restore channel attribute cleanup checks; name network error codes

Brings back the PR's afterEach/afterAll error handling that the main merge replaced, and makes a no-response error show its codes (an AggregateError has an empty message).

* E2E: run channel attribute creation and editing specs on server B

Their 11 required-attribute tests could not run on the shared servers. Both specs now run on the mutation server with ChannelAttributesRequired on for their run, and the tests are re-enabled. setChannelAttributesRequired moves to the shared helper.

* Check header chips instead of their wrapper and use toExist for the create screen in channel attribute E2E

---------

Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
2026-10-30 15:03:55 +01:00

376 lines
9.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type {DatabaseType} from '@constants/database';
import type AppDataOperator from '@database/operator/app_data_operator';
import type ServerDataOperator from '@database/operator/server_data_operator';
import type {Database} from '@nozbe/watermelondb';
import type Model from '@nozbe/watermelondb/Model';
import type {Clause} from '@nozbe/watermelondb/QueryDescription';
import type {Class} from '@nozbe/watermelondb/types';
import type {CustomProfileField, CustomProfileAttribute} from '@typings/api/custom_profile_attributes';
import type System from '@typings/database/models/servers/system';
export type SyncStatus = 'synced' | 'pending' | 'failed';
export type WithDatabaseArgs = { database: Database }
export type CreateServerDatabaseConfig = {
dbName: string;
dbType?: DatabaseType;
displayName?: string;
serverUrl?: string;
identifier?: string;
};
export type RegisterServerDatabaseArgs = {
databaseFilePath: string;
displayName: string;
serverUrl: string;
identifier?: string;
};
export type AppDatabase = {
database: Database;
operator: AppDataOperator;
};
export type ServerDatabase = {
database: Database;
operator: ServerDataOperator;
}
export type ServerDatabases = {
[x: string]: ServerDatabase | undefined;
};
export type TransformerArgs<T extends Model, R extends RawValue> = {
action: string;
database: Database;
fieldsMapper?: (model: Model) => void;
tableName?: string;
value: RecordPair<T, R>;
};
export type PrepareBaseRecordArgs<T extends Model, R extends RawValue> = TransformerArgs<T, R> & {
fieldsMapper: (model: Model) => void;
}
export type OperationArgs<T extends Model, R extends RawValue> = {
tableName: string;
createRaws?: Array<RecordPair<T, R>>;
updateRaws?: Array<RecordPair<T, R>>;
deleteRaws?: T[];
transformer: (args: TransformerArgs<T, R>) => Promise<T>;
};
export type Models = Array<Class<Model>>;
// The elements needed to create a new database
export type CreateServerDatabaseArgs = {
config: CreateServerDatabaseConfig;
shouldAddToAppDatabase?: boolean;
};
export type HandleReactionsArgs = {
prepareRecordsOnly: boolean;
postsReactions?: ReactionsPerPost[];
skipSync?: boolean;
};
export type HandleFilesArgs = {
files?: FileInfo[];
prepareRecordsOnly: boolean;
};
export type HandlePostsArgs = {
actionType: string;
order?: string[];
previousPostId?: string;
posts?: Post[];
prepareRecordsOnly?: boolean;
// Set when the posts are fetched on their own (e.g. the post behind a permalink preview)
// rather than as part of a channel's timeline, so they must not extend or create a
// PostsInChannel interval that claims continuity the client does not have.
skipPostsInChannel?: boolean;
// Supplied only for responses that went through ABAC sanitization; local mutations omit it so the
// stored value is preserved. Never sent to the server.
redactionVerifiedEpoch?: number;
};
// Threaded from handlePosts to the transformer on the raw itself, because transformers take no
// arguments beyond the record pair. Not part of the server-facing Post contract.
export type PostWithRedactionEpoch = Post & {redaction_verified_epoch?: number};
export type HandleThreadsArgs = {
threads?: ThreadWithLastFetchedAt[];
prepareRecordsOnly?: boolean;
teamId?: string;
};
export type HandleThreadParticipantsArgs = {
prepareRecordsOnly: boolean;
skipSync?: boolean;
threadsParticipants: ParticipantsPerThread[];
};
export type HandleThreadInTeamArgs = {
threadsMap?: Record<string, Thread[]>;
prepareRecordsOnly?: boolean;
};
export type HandleTeamThreadsSyncArgs = {
data: TeamThreadsSync[];
prepareRecordsOnly?: boolean;
};
export type SanitizeReactionsArgs = {
database: Database;
post_id: string;
rawReactions: Reaction[];
skipSync?: boolean;
};
export type SanitizeThreadParticipantsArgs = {
database: Database;
skipSync?: boolean;
thread_id: $ID<Thread>;
rawParticipants: ThreadParticipant[];
}
export type ChainPostsArgs = {
order?: string[];
previousPostId: string;
posts: Post[];
};
export type SanitizePostsArgs = {
orders: string[];
posts: Post[];
};
export type IdenticalRecordArgs<T extends Model, R extends RawValue> = {
existingRecord: T;
newValue: R;
tableName: string;
};
export type RetrieveRecordsArgs = {
database: Database;
tableName: string;
condition: Clause;
};
export type ProcessRecordsArgs<R extends RawValue> = {
createOrUpdateRawValues: R[];
deleteRawValues: R[];
tableName: string;
fieldName: string;
buildKeyRecordBy?: (obj: Record<string, any>) => string;
shouldUpdate?: (existing: Record<string, any>, newRaw: Record<string, any>) => boolean;
};
export type HandleRecordsArgs<T extends Model, R extends RawValue> = {
buildKeyRecordBy?: (obj: Record<string, any>) => string;
fieldName: string;
transformer: (args: TransformerArgs<T, R>) => Promise<T>;
createOrUpdateRawValues: R[];
deleteRawValues?: R[];
tableName: string;
prepareRecordsOnly: boolean;
shouldUpdate?: (existingRecord: T, newRaw: RawValue) => boolean;
};
export type RangeOfValueArgs = {
raws: RawValue[];
fieldName: string;
};
export type RecordPair<T extends Model, R extends RawValue> = {
record?: T;
raw: R;
};
type PrepareOnly = {
prepareRecordsOnly: boolean;
}
export type HandleInfoArgs = PrepareOnly & {
info?: AppInfo[];
}
export type HandleGlobalArgs = PrepareOnly & {
globals?: IdValue[];
}
export type HandleRoleArgs = PrepareOnly & {
roles?: Role[];
}
export type HandleCustomEmojiArgs = PrepareOnly & {
emojis?: CustomEmoji[];
}
export type HandleSystemArgs = PrepareOnly & {
systems?: IdValue[];
}
export type HandleConfigArgs = PrepareOnly & {
configs: IdValue[];
configsToDelete: IdValue[];
}
export type HandleMyChannelArgs = PrepareOnly & {
channels?: Channel[];
myChannels?: ChannelMembership[];
isCRTEnabled?: boolean;
};
export type HandleChannelInfoArgs = PrepareOnly &{
channelInfos?: Array<Partial<ChannelInfo>>;
};
export type HandleMyChannelSettingsArgs = PrepareOnly & {
settings?: ChannelMembership[];
};
export type HandleChannelArgs = PrepareOnly & {
channels?: Channel[];
};
export type HandleChannelBookmarkArgs = PrepareOnly & {
bookmarks?: ChannelBookmarkWithFileInfo[];
};
export type HandleCategoryArgs = PrepareOnly & {
categories?: Category[];
};
export type HandleGroupArgs = PrepareOnly & {
groups?: Group[];
};
export type HandleGroupChannelsForChannelArgs = PrepareOnly & {
channelId: string;
groups?: Array<Pick<Group, 'id'>>;
}
export type HandleGroupMembershipForMemberArgs = PrepareOnly & {
userId: string;
groups?: Array<Pick<Group, 'id'>>;
}
export type HandleGroupTeamsForTeamArgs = PrepareOnly & {
teamId: string;
groups?: Array<Pick<Group, 'id'>>;
}
export type HandleCategoryChannelArgs = PrepareOnly & {
categoryChannels?: CategoryChannel[];
};
export type HandleMyTeamArgs = PrepareOnly & {
myTeams?: MyTeam[];
};
export type HandleTeamSearchHistoryArgs = PrepareOnly &{
teamSearchHistories?: TeamSearchHistory[];
};
export type HandleTeamChannelHistoryArgs = PrepareOnly & {
teamChannelHistories?: TeamChannelHistory[];
};
export type HandleTeamArgs = PrepareOnly & {
teams?: Team[];
};
export type HandleChannelMembershipArgs = PrepareOnly & {
channelMemberships?: Array<Pick<ChannelMembership, 'user_id' | 'channel_id' | 'scheme_admin'>>;
};
export type HandleTeamMembershipArgs = PrepareOnly & {
teamMemberships?: TeamMembership[];
};
export type HandlePreferencesArgs = PrepareOnly & {
preferences?: PreferenceType[];
sync?: boolean;
};
export type HandleUsersArgs = PrepareOnly & {
users?: UserProfile[];
};
export type HandleDraftArgs = PrepareOnly & {
drafts?: Draft[];
};
export type HandleScheduledPostsArgs = PrepareOnly & {
actionType: string;
scheduledPosts?: ScheduledPost[];
includeDirectChannelPosts?: boolean;
};
export type HandleScheduledPostErrorCodeArgs = PrepareOnly & {
scheduledPostId: string;
errorCode: string;
}
export type HandleCustomProfileFieldsArgs = PrepareOnly & {
fields?: CustomProfileField[];
};
export type HandleCustomProfileAttributesArgs = PrepareOnly & {
attributes?: CustomProfileAttribute[];
};
export type HandlePropertyFieldsArgs = PrepareOnly & {
fields?: PropertyField[];
groupId?: string;
// Restricts groupId-driven pruning to fields whose object_type is in this
// list. The access_control group also holds user/session fields owned by
// other features; a groupId-only prune would delete those too whenever a
// caller's fetch only covers a subset of object types. Optional so callers
// that genuinely fetch every object type in the group are unaffected.
objectTypes?: PropertyFieldObjectType[];
};
export type HandlePropertyValuesArgs = PrepareOnly & {
values?: PropertyValue[];
targetId?: string;
groupId?: string;
};
export type LoginArgs = {
config: Partial<ClientConfig>;
ldapOnly?: boolean;
license: Partial<ClientLicense>;
loginId: string;
mfaToken?: string;
password: string;
serverDisplayName: string;
};
export type ServerUrlChangedArgs = {
configRecord: System;
licenseRecord: System;
selectServerRecord: System;
serverUrl: string;
};
export type GetDatabaseConnectionArgs = {
serverUrl: string;
connectionName?: string;
setAsActiveDatabase: boolean;
}
export type ProcessRecordResults<T extends Model, R extends RawValue> = {
createRaws: Array<RecordPair<T, R>>;
updateRaws: Array<RecordPair<T, R>>;
deleteRaws: T[];
}