diff --git a/keyserver/src/updaters/entry-updaters.js b/keyserver/src/updaters/entry-updaters.js --- a/keyserver/src/updaters/entry-updaters.js +++ b/keyserver/src/updaters/entry-updaters.js @@ -157,7 +157,7 @@ `), ); } - const updatedEntryInfo = { + const updatedEntryInfo: RawEntryInfo = { ...entryInfo, text: request.text, }; diff --git a/lib/types/entry-types.js b/lib/types/entry-types.js --- a/lib/types/entry-types.js +++ b/lib/types/entry-types.js @@ -1,6 +1,6 @@ // @flow -import t, { type TInterface } from 'tcomb'; +import t, { type TInterface, type TUnion } from 'tcomb'; import { type Platform, isWebPlatform } from './device-types.js'; import { @@ -21,34 +21,57 @@ } from '../utils/date-utils.js'; import { tUserID, tID, tShape } from '../utils/validation-utils.js'; -export type RawEntryInfo = { - id?: string, // null if local copy without ID yet - localID?: string, // for optimistic creations - threadID: string, - text: string, - year: number, - month: number, // 1-indexed - day: number, // 1-indexed - creationTime: number, // millisecond timestamp - creatorID: string, - deleted: boolean, +export type RawEntryInfoBase = { + +id?: string, // null if local copy without ID yet + +localID?: string, // for optimistic creations + +threadID: string, + +text: string, + +year: number, + +month: number, // 1-indexed + +day: number, // 1-indexed + +creationTime: number, // millisecond timestamp + +creatorID: string, + +deleted: boolean, +}; +const rawEntryInfoBaseValidatorShape = { + id: t.maybe(tID), + localID: t.maybe(t.String), + threadID: tID, + text: t.String, + year: t.Number, + month: t.Number, + day: t.Number, + creationTime: t.Number, + creatorID: tUserID, + deleted: t.Boolean, }; + +export type ThinRawEntryInfo = RawEntryInfoBase; +const thinRawEntryInfoValidator: TInterface = + tShape({ + ...rawEntryInfoBaseValidatorShape, + }); + +export type ThickRawEntryInfo = $ReadOnly<{ + ...RawEntryInfoBase, + +thick: true, + +lastUpdatedTime: number, +}>; +const thickRawEntryInfoValidator: TInterface = + tShape({ + ...rawEntryInfoBaseValidatorShape, + thick: t.Boolean, + lastUpdatedTime: t.Number, + }); + +export type RawEntryInfo = ThinRawEntryInfo | ThickRawEntryInfo; +export const rawEntryInfoValidator: TUnion = t.union([ + thinRawEntryInfoValidator, + thickRawEntryInfoValidator, +]); export type RawEntryInfos = { +[id: string]: RawEntryInfo, }; -export const rawEntryInfoValidator: TInterface = - tShape({ - id: t.maybe(tID), - localID: t.maybe(t.String), - threadID: tID, - text: t.String, - year: t.Number, - month: t.Number, - day: t.Number, - creationTime: t.Number, - creatorID: tUserID, - deleted: t.Boolean, - }); export type EntryInfo = { id?: string, // null if local copy without ID yet