-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathindex.d.ts
More file actions
40 lines (32 loc) · 1.64 KB
/
index.d.ts
File metadata and controls
40 lines (32 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { ColumnName, ColumnSchema, TableSchema } from '../Schema'
import type { RecordId, SyncStatus } from '../Model'
// Raw object representing a model record, coming from an untrusted source
// (disk, sync, user data). Before it can be used to create a Model instance
// it must be sanitized (with `sanitizedRaw`) into a RawRecord
export type DirtyRaw = { [key: string]: any }
// These fields are ALWAYS present in records of any collection.
type _RawRecord = {
id: RecordId
_status: SyncStatus
// _changed is used by default pull conflict resolution and determines columns for which local
// changes will override remote changes
_changed: string
}
// Raw object representing a model record. A RawRecord is guaranteed by the type system
// to be safe to use (sanitied with `sanitizedRaw`):
// - it has exactly the fields described by TableSchema (+ standard fields)
// - every field is exactly the type described by ColumnSchema (string, number, or boolean)
// - … and the same optionality (will not be null unless isOptional: true)
export type RawRecord = _RawRecord
// Transforms a dirty raw record object into a trusted sanitized RawRecord according to passed TableSchema
export function sanitizedRaw(dirtyRaw: DirtyRaw, tableSchema: TableSchema): RawRecord
// Modifies passed rawRecord by setting sanitized `value` to `columnName`
// Note: Assumes columnName exists and columnSchema matches the name
export function setRawSanitized(
rawRecord: RawRecord,
columnName: ColumnName,
value: any,
columnSchema: ColumnSchema,
): void
export type NullValue = null | '' | 0 | false
export function nullValue(columnSchema: ColumnSchema): NullValue