Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32559641
D7571.1767285124.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D7571.1767285124.diff
View Options
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,5 +1,7 @@
// @flow
+import t, { type TInterface } from 'tcomb';
+
import { type Platform, isWebPlatform } from './device-types.js';
import { type CalendarFilter, defaultCalendarFilters } from './filter-types.js';
import type { RawMessageInfo } from './message-types.js';
@@ -13,6 +15,7 @@
fifteenDaysLater,
thisMonthDates,
} from '../utils/date-utils.js';
+import { tID, tShape } from '../utils/validation-utils.js';
export type RawEntryInfo = {
id?: string, // null if local copy without ID yet
@@ -26,6 +29,19 @@
creatorID: string,
deleted: boolean,
};
+export const rawEntryInfoValidator: TInterface<RawEntryInfo> =
+ tShape<RawEntryInfo>({
+ 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: t.String,
+ deleted: t.Boolean,
+ });
export type EntryInfo = {
id?: string, // null if local copy without ID yet
diff --git a/lib/types/validation.test.js b/lib/types/validation.test.js
--- a/lib/types/validation.test.js
+++ b/lib/types/validation.test.js
@@ -2,6 +2,7 @@
import _findKey from 'lodash/fp/findKey.js';
+import { rawEntryInfoValidator } from './entry-types.js';
import {
imageValidator,
videoValidator,
@@ -633,3 +634,24 @@
).toBe(false);
});
});
+
+describe('entry validation', () => {
+ const entry = {
+ id: '92860',
+ threadID: '85068',
+ text: 'text',
+ year: 2023,
+ month: 4,
+ day: 2,
+ creationTime: 1682082939882,
+ creatorID: '83853',
+ deleted: false,
+ };
+
+ it('should validate correct entry', () => {
+ expect(rawEntryInfoValidator.is(entry)).toBe(true);
+ });
+ it('should not validate incorrect entry', () => {
+ expect(rawEntryInfoValidator.is({ ...entry, threadID: 0 })).toBe(false);
+ });
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 1, 4:32 PM (13 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5876829
Default Alt Text
D7571.1767285124.diff (1 KB)
Attached To
Mode
D7571: [lib] Introduce raw entry info validators
Attached
Detach File
Event Timeline
Log In to Comment