Page MenuHomePhabricator

D10928.id37278.diff
No OneTemporary

D10928.id37278.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,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 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,72 @@
+// @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 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';
+
+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,45 @@
+// @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 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,66 @@
+// @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 Failure = {
+ +id: string,
+ +error: string,
+};
+
+export const failureValidator: TInterface<Failure> = tShape<Failure>({
+ id: t.String,
+ error: t.String,
+});
+
+export type IdentitySearchUser = {
+ +userID: string,
+ +username: string,
+};
+
+export const userValidator: TInterface<IdentitySearchUser> =
+ tShape<IdentitySearchUser>({
+ userID: t.String,
+ username: t.String,
+ });
+
+export type SearchResult = {
+ +id: string,
+ +hits: $ReadOnlyArray<IdentitySearchUser>,
+};
+
+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,
+ }),
+]);
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

Mime Type
text/plain
Expires
Thu, Dec 19, 4:51 AM (21 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675343
Default Alt Text
D10928.id37278.diff (10 KB)

Event Timeline