Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3486072
D10928.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D10928.diff
View Options
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,33 @@
+// @flow
+
+/*
+ * This file defines types and validation for the auth message sent
+ * from the client to the Identity Search WebSocket server.
+ * 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/auth_messages.rs`.
+ *
+ * If you edit the definitions in one file,
+ * please make sure to update the corresponding definitions in the other.
+ *
+ */
+
+import type { TInterface } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type IdentitySearchAuthMessage = {
+ +type: 'IdentitySearchAuthMessage',
+ +userID: string,
+ +deviceID: string,
+ +accessToken: string,
+};
+
+export const identityAuthMessageValidator: TInterface<IdentitySearchAuthMessage> =
+ tShape<IdentitySearchAuthMessage>({
+ type: tString('IdentitySearchAuthMessage'),
+ 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,76 @@
+// @flow
+
+/*
+ * 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.
+ *
+ */
+
+import type { TUnion } from 'tcomb';
+import t from 'tcomb';
+
+import {
+ type IdentitySearchAuthMessage,
+ identityAuthMessageValidator,
+} from './auth-message-types.js';
+import {
+ type IdentitySearchQuery,
+ identitySearchQueryValidator,
+} from './search-query-types.js';
+import {
+ type IdentitySearchResponse,
+ identitySearchResponseValidator,
+} 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';
+
+export const identitySearchMessageToClientTypes = Object.freeze({
+ CONNECTION_INITIALIZATION_RESPONSE: 'ConnectionInitializationResponse',
+ SUCCESS: 'Success',
+ ERROR: 'Error',
+ SEARCH_RESPONSE: 'IdentitySearchResponse',
+ HEARTBEAT: 'Heartbeat',
+});
+
+export const identitySearchMessageToClientValidator: TUnion<IdentitySearchMessageToClient> =
+ t.union([
+ connectionInitializationResponseValidator,
+ identitySearchResponseValidator,
+ heartbeatValidator,
+ ]);
+
+export type IdentitySearchMessageToClient =
+ | ConnectionInitializationResponse
+ | IdentitySearchResponse
+ | Heartbeat;
+
+export const identitySearchMessageToServerTypes = Object.freeze({
+ IDENTITY_SEARCH_AUTH_MESSAGE: 'IdentitySearchAuthMessage',
+ IDENTITY_SEARCH_QUERY: 'IdentitySearchQuery',
+ IDENTITY_SEARCH_PREFIX: 'IdentitySearchPrefix',
+ HEARTBEAT: 'Heartbeat',
+});
+
+export const identitySearchMessageToServerValidator: TUnion<IdentitySearchMessageToServer> =
+ t.union([
+ identityAuthMessageValidator,
+ identitySearchQueryValidator,
+ heartbeatValidator,
+ ]);
+
+export type IdentitySearchMessageToServer =
+ | IdentitySearchAuthMessage
+ | IdentitySearchQuery
+ | 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,47 @@
+// @flow
+
+/*
+ * This file defines types and validation for the search query message sent
+ * from the client to the Identity Search WebSocket server.
+ * 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/search_query.rs`.
+ *
+ * If you edit the definitions in one file,
+ * please make sure to update the corresponding definitions in the other.
+ *
+ */
+
+import type { TInterface } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type IdentitySearchMethod = IdentitySearchPrefix;
+
+export type IdentitySearchPrefix = {
+ +type: 'IdentitySearchPrefix',
+ +prefix: string,
+};
+
+export const identityPrefixValidator: TInterface<IdentitySearchPrefix> =
+ tShape<IdentitySearchPrefix>({
+ type: tString('IdentitySearchPrefix'),
+ prefix: t.String,
+ });
+
+export const identitySearchMethodValidator: TInterface<IdentitySearchPrefix> =
+ identityPrefixValidator;
+
+export type IdentitySearchQuery = {
+ +type: 'IdentitySearchQuery',
+ +id: string,
+ +searchMethod: IdentitySearchMethod,
+};
+
+export const identitySearchQueryValidator: TInterface<IdentitySearchQuery> =
+ tShape<IdentitySearchQuery>({
+ type: tString('IdentitySearchQuery'),
+ id: t.String,
+ searchMethod: identitySearchMethodValidator,
+ });
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,76 @@
+// @flow
+
+/*
+ * This file defines types and validation for the search response message
+ * sent from the Identity Search WebSocket server 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/search_response.rs`.
+ *
+ * If you edit the definitions in one file,
+ * please make sure to update the corresponding definitions in the other.
+ *
+ */
+
+import type { TInterface, TUnion } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type IdentitySearchFailure = {
+ +id: string,
+ +error: string,
+};
+
+export const identityFailureValidator: TInterface<IdentitySearchFailure> =
+ tShape<IdentitySearchFailure>({
+ id: t.String,
+ error: t.String,
+ });
+
+export type IdentitySearchUser = {
+ +userID: string,
+ +username: string,
+};
+
+export const identitySearchUserValidator: TInterface<IdentitySearchUser> =
+ tShape<IdentitySearchUser>({
+ userID: t.String,
+ username: t.String,
+ });
+
+export type IdentitySearchResult = {
+ +id: string,
+ +hits: $ReadOnlyArray<IdentitySearchUser>,
+};
+
+export const identitySearchResultValidator: TInterface<IdentitySearchResult> =
+ tShape<IdentitySearchResult>({
+ id: t.String,
+ hits: t.list(identitySearchUserValidator),
+ });
+
+type IdentitySearchResponseSuccess = {
+ +type: 'Success',
+ +data: IdentitySearchResult,
+};
+type IdentitySearchResponseError = {
+ +type: 'Error',
+ +data: IdentitySearchFailure,
+};
+
+export type IdentitySearchResponse =
+ | IdentitySearchResponseSuccess
+ | IdentitySearchResponseError;
+
+export const identitySearchResponseValidator: TUnion<IdentitySearchResponse> =
+ t.union([
+ tShape<IdentitySearchResponseSuccess>({
+ type: tString('Success'),
+ data: identitySearchResultValidator,
+ }),
+ tShape<IdentitySearchResponseError>({
+ type: tString('Error'),
+ data: identityFailureValidator,
+ }),
+ ]);
diff --git a/shared/identity_search_messages/src/messages/auth_messages.rs b/shared/identity_search_messages/src/messages/auth_messages.rs
--- a/shared/identity_search_messages/src/messages/auth_messages.rs
+++ b/shared/identity_search_messages/src/messages/auth_messages.rs
@@ -1,4 +1,16 @@
-//! Message sent by client to authenticate with Identity Search Server
+//! Auth Message sent by Client to authenticate with Identity Search Server via WebSocket.
+
+//
+// This file defines structs and enums for the auth message sent
+// from the Client to the Identity Search WebSocket server.
+// The definitions in this file should remain in sync
+// with the types and validators defined in the corresponding
+// JavaScript file at `lib/types/identity-search/auth-message-types.js`.
+//
+// If you edit the definitions in one file,
+// please make sure to update the corresponding definitions in the other.
+//
+//
use serde::{Deserialize, Serialize};
diff --git a/shared/identity_search_messages/src/messages/mod.rs b/shared/identity_search_messages/src/messages/mod.rs
--- a/shared/identity_search_messages/src/messages/mod.rs
+++ b/shared/identity_search_messages/src/messages/mod.rs
@@ -1,4 +1,16 @@
-//! Messages sent between Client and Identity Search Server
+//! Messages sent between Client and Identity Search Server via WebSocket.
+
+//
+// This file defines structs and enums for messages sent
+// to Identity Search WebSocket server and messages sent to Client.
+// The definitions in this file should remain in sync
+// with the types and validators defined in the corresponding
+// JavaScript file at `lib/types/identity-search/messages.js`.
+//
+// If you edit the definitions in one file,
+// please make sure to update the corresponding definitions in the other.
+//
+//
pub mod auth_messages;
pub mod search_query;
diff --git a/shared/identity_search_messages/src/messages/search_query.rs b/shared/identity_search_messages/src/messages/search_query.rs
--- a/shared/identity_search_messages/src/messages/search_query.rs
+++ b/shared/identity_search_messages/src/messages/search_query.rs
@@ -1,4 +1,15 @@
-//! Search Request Messages sent by Client to Identity Search via WebSocket.
+//! Search Query Message sent by Client to Identity Search via WebSocket.
+
+//
+// This file defines structs and enums for the search query message sent
+// from the Client to the Identity Search WebSocket server.
+// The definitions in this file should remain in sync
+// with the types and validators defined in the corresponding
+// JavaScript file at `lib/types/identity-search/search-query-types.js`.
+//
+// If you edit the definitions in one file,
+// please make sure to update the corresponding definitions in the other.
+//
use serde::{Deserialize, Serialize};
diff --git a/shared/identity_search_messages/src/messages/search_response.rs b/shared/identity_search_messages/src/messages/search_response.rs
--- a/shared/identity_search_messages/src/messages/search_response.rs
+++ b/shared/identity_search_messages/src/messages/search_response.rs
@@ -1,4 +1,16 @@
-//! Search Result Messages sent by Identity Search via WebSocket.
+//! Search Response Message sent by Identity Search via WebSocket to Client.
+
+//
+// This file defines structs and enums for the search response message
+// sent from the Identity Search WebSocket server to Client.
+// The definitions in this file should remain in sync
+// with the types and validators defined in the corresponding JavaScript file at
+// `lib/types/identity-search/search-response-types.js`.
+//
+// If you edit the definitions in one file,
+// please make sure to update the corresponding definitions in the other.
+//
+//
use serde::{Deserialize, Serialize};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 2:44 AM (21 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675098
Default Alt Text
D10928.diff (11 KB)
Attached To
Mode
D10928: [lib] Add types for identity search websocket server
Attached
Detach File
Event Timeline
Log In to Comment