Page MenuHomePhabricator

D10928.id36869.diff
No OneTemporary

D10928.id36869.diff

diff --git a/lib/types/identity-search/auth-message-types.js b/lib/types/identity-search/auth-message-types.js
new file mode 100644
--- /dev/null
+++ b/lib/types/identity-search/auth-message-types.js
@@ -0,0 +1,21 @@
+// @flow
+
+import type { TInterface } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type AuthMessage = {
+ +type: 'AuthMessage',
+ +userID: string,
+ +deviceID: string,
+ +accessToken: string,
+};
+
+export const authMessageValidator: TInterface<AuthMessage> =
+ tShape<AuthMessage>({
+ type: tString('AuthMessage'),
+ userID: t.String,
+ deviceID: t.String,
+ accessToken: t.String,
+ });
diff --git a/lib/types/identity-search/messages.js b/lib/types/identity-search/messages.js
new file mode 100644
--- /dev/null
+++ b/lib/types/identity-search/messages.js
@@ -0,0 +1,71 @@
+// @flow
+
+import type { TUnion } from 'tcomb';
+import t from 'tcomb';
+
+import {
+ type AuthMessage,
+ authMessageValidator,
+} from './auth-message-types.js';
+import {
+ type SearchQuery,
+ searchQueryValidator,
+} from './search-query-types.js';
+import {
+ type SearchResponse,
+ searchResponseValidator,
+} from './search-response-types.js';
+import {
+ type ConnectionInitializationResponse,
+ connectionInitializationResponseValidator,
+} from '../websocket/connection-initialization-response-types.js';
+import {
+ type Heartbeat,
+ heartbeatValidator,
+} from '../websocket/heartbeat-types.js';
+
+/*
+ * This file defines types and validation for messages sent
+ * to Identity Search WebSocket server and messages sent to client.
+ * The definitions in this file should remain in sync
+ * with the structures defined in the corresponding
+ * Rust file at `shared/identity_search_messages/src/messages/mod.rs`.
+ *
+ * If you edit the definitions in one file,
+ * please make sure to update the corresponding definitions in the other.
+ *
+ */
+export const identitySearchMessageToClientTypes = Object.freeze({
+ CONNECTION_INITIALIZATION_RESPONSE: 'ConnectionInitializationResponse',
+ SUCCESS: 'Success',
+ ERROR: 'Error',
+ SEARCH_RESPONSE: 'SearchResponse',
+ HEARTBEAT: 'Heartbeat',
+});
+
+export const identitySearchMessageToClientValidator: TUnion<IdentitySearchMessageToClient> =
+ t.union([
+ connectionInitializationResponseValidator,
+ searchResponseValidator,
+ heartbeatValidator,
+ ]);
+
+export type IdentitySearchMessageToClient =
+ | ConnectionInitializationResponse
+ | SearchResponse
+ | Heartbeat;
+
+export const identitySearchMessageToServerTypes = Object.freeze({
+ AUTH_MESSAGE: 'AuthMessage',
+ SEARCH_QUERY: 'SearchQuery',
+ PREFIX: 'Prefix',
+ HEARTBEAT: 'Heartbeat',
+});
+
+export const identitySearchMessageToServerValidator: TUnion<IdentitySearchMessageToServer> =
+ t.union([authMessageValidator, searchQueryValidator, heartbeatValidator]);
+
+export type IdentitySearchMessageToServer =
+ | AuthMessage
+ | SearchQuery
+ | Heartbeat;
diff --git a/lib/types/identity-search/search-query-types.js b/lib/types/identity-search/search-query-types.js
new file mode 100644
--- /dev/null
+++ b/lib/types/identity-search/search-query-types.js
@@ -0,0 +1,33 @@
+// @flow
+
+import type { TInterface } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type SearchMethod = Prefix;
+
+export type Prefix = {
+ +type: 'Prefix',
+ +prefix: string,
+};
+
+export const prefixValidator: TInterface<Prefix> = tShape<Prefix>({
+ type: tString('Prefix'),
+ prefix: t.String,
+});
+
+export const searchMethodValidator: TInterface<Prefix> = prefixValidator;
+
+export type SearchQuery = {
+ +type: 'SearchQuery',
+ +id: string,
+ +searchMethod: SearchMethod,
+};
+
+export const searchQueryValidator: TInterface<SearchQuery> =
+ tShape<SearchQuery>({
+ type: tString('SearchQuery'),
+ id: t.String,
+ searchMethod: searchMethodValidator,
+ });
diff --git a/lib/types/identity-search/search-response-types.js b/lib/types/identity-search/search-response-types.js
new file mode 100644
--- /dev/null
+++ b/lib/types/identity-search/search-response-types.js
@@ -0,0 +1,53 @@
+// @flow
+
+import type { TInterface, TUnion } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type Failure = {
+ +id: string,
+ +error: string,
+};
+
+export const failureValidator: TInterface<Failure> = tShape<Failure>({
+ id: t.String,
+ error: t.String,
+});
+
+export type User = {
+ +userID: string,
+ +username: string,
+};
+
+export const userValidator: TInterface<User> = tShape<User>({
+ userID: t.String,
+ username: t.String,
+});
+
+export type SearchResult = {
+ +id: string,
+ +hits: $ReadOnlyArray<User>,
+};
+
+export const searchResultValidator: TInterface<SearchResult> =
+ tShape<SearchResult>({
+ id: t.String,
+ hits: t.list(userValidator),
+ });
+
+type SearchResponseSuccess = { +type: 'Success', +data: SearchResult };
+type SearchResponseError = { +type: 'Error', +data: Failure };
+
+export type SearchResponse = SearchResponseSuccess | SearchResponseError;
+
+export const searchResponseValidator: TUnion<SearchResponse> = t.union([
+ tShape<SearchResponseSuccess>({
+ type: tString('Success'),
+ data: searchResultValidator,
+ }),
+ tShape<SearchResponseError>({
+ type: tString('Error'),
+ data: failureValidator,
+ }),
+]);

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 6:09 AM (21 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675624
Default Alt Text
D10928.id36869.diff (5 KB)

Event Timeline