Page MenuHomePhabricator

D10928.id36631.diff
No OneTemporary

D10928.id36631.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,68 @@
+// @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 SearchResult,
+ searchResultValidator,
+} from './search-result-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',
+ SEARCH_RESULT: 'SearchResult',
+ HEARTBEAT: 'Heartbeat',
+});
+
+export const identitySearchMessageToClientValidator: TUnion<IdentitySearchMessageToClient> =
+ t.union([
+ connectionInitializationResponseValidator,
+ searchResultValidator,
+ heartbeatValidator,
+ ]);
+
+export type IdentitySearchMessageToClient =
+ | ConnectionInitializationResponse
+ | SearchResult
+ | Heartbeat;
+
+export const identitySearchMessageToServerTypes = Object.freeze({
+ AUTH_MESSAGE: 'AuthMessage',
+ SEARCH_QUERY: 'SearchQuery',
+ 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,20 @@
+// @flow
+
+import type { TInterface } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type SearchQuery = Prefix;
+
+export type Prefix = {
+ +type: 'Prefix',
+ +prefix: string,
+};
+
+export const prefixValidator: TInterface<Prefix> = tShape<Prefix>({
+ type: tString('Prefix'),
+ prefix: t.String,
+});
+
+export const searchQueryValidator: TInterface<Prefix> = prefixValidator;
diff --git a/lib/types/identity-search/search-result-types.js b/lib/types/identity-search/search-result-types.js
new file mode 100644
--- /dev/null
+++ b/lib/types/identity-search/search-result-types.js
@@ -0,0 +1,27 @@
+// @flow
+
+import type { TInterface } from 'tcomb';
+import t from 'tcomb';
+
+import { tShape, tString } from '../../utils/validation-utils.js';
+
+export type User = {
+ +userID: string,
+ +username: string,
+};
+
+export type SearchResult = {
+ +type: 'SearchResult',
+ +payload: $ReadOnlyArray<User>,
+};
+
+export const userValidator: TInterface<User> = tShape<User>({
+ userID: t.String,
+ username: t.String,
+});
+
+export const searchResultValidator: TInterface<SearchResult> =
+ tShape<SearchResult>({
+ type: tString('SearchResult'),
+ payload: t.list(userValidator),
+ });

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 5:55 AM (20 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675563
Default Alt Text
D10928.id36631.diff (4 KB)

Event Timeline