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 { @@ -19,37 +19,65 @@ fifteenDaysLater, thisMonthDates, } from '../utils/date-utils.js'; -import { tUserID, tID, tShape } from '../utils/validation-utils.js'; +import { tUserID, tID, tShape, tBool } 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, }; -export type RawEntryInfos = { - +[id: string]: RawEntryInfo, +const rawEntryInfoBaseValidatorShape = { + 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 const rawEntryInfoValidator: TInterface = - tShape({ + +export type ThinRawEntryInfo = $ReadOnly<{ + ...RawEntryInfoBase, + id?: string, +}>; +const thinRawEntryInfoValidator: TInterface = + tShape({ + ...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 ThickRawEntryInfo = $ReadOnly<{ + ...RawEntryInfoBase, + +id: string, + +thick: true, + +lastUpdatedTime: number, +}>; +const thickRawEntryInfoValidator: TInterface = + tShape({ + ...rawEntryInfoBaseValidatorShape, + id: t.String, + thick: tBool(true), + lastUpdatedTime: t.Number, + }); + +export type RawEntryInfo = ThinRawEntryInfo | ThickRawEntryInfo; +export const rawEntryInfoValidator: TUnion = t.union([ + thinRawEntryInfoValidator, + thickRawEntryInfoValidator, +]); +export type RawEntryInfos = { + +[id: string]: RawEntryInfo, +}; + export type EntryInfo = { id?: string, // null if local copy without ID yet localID?: string, // for optimistic creations