2022-10-26 14:41:38 +00:00
|
|
|
import { CellValue } from "./GristData";
|
2021-10-15 09:31:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON schema for api /record endpoint. Used in POST method for adding new records.
|
|
|
|
*/
|
|
|
|
export interface NewRecord {
|
2022-07-27 19:29:20 +00:00
|
|
|
/**
|
|
|
|
* Initial values of cells in record. Optional, if not set cells are left
|
|
|
|
* blank.
|
|
|
|
*/
|
|
|
|
fields?: { [coldId: string]: CellValue };
|
2021-10-15 09:31:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 19:24:14 +00:00
|
|
|
export interface NewRecordWithStringId {
|
|
|
|
id?: string; // tableId or colId
|
|
|
|
/**
|
|
|
|
* Initial values of cells in record. Optional, if not set cells are left
|
|
|
|
* blank.
|
|
|
|
*/
|
|
|
|
fields?: { [coldId: string]: CellValue };
|
|
|
|
}
|
|
|
|
|
2021-10-15 09:31:13 +00:00
|
|
|
/**
|
|
|
|
* JSON schema for api /record endpoint. Used in PATCH method for updating existing records.
|
|
|
|
*/
|
|
|
|
export interface Record {
|
|
|
|
id: number;
|
|
|
|
fields: { [coldId: string]: CellValue };
|
|
|
|
}
|
|
|
|
|
2022-10-20 19:24:14 +00:00
|
|
|
export interface RecordWithStringId {
|
|
|
|
id: string; // tableId or colId
|
|
|
|
fields: { [coldId: string]: CellValue };
|
|
|
|
}
|
|
|
|
|
2022-02-11 13:10:53 +00:00
|
|
|
/**
|
|
|
|
* JSON schema for api /record endpoint. Used in PUT method for adding or updating records.
|
|
|
|
*/
|
|
|
|
export interface AddOrUpdateRecord {
|
2022-07-27 19:29:20 +00:00
|
|
|
/**
|
|
|
|
* The values we expect to have in particular columns, either by matching with
|
|
|
|
* an existing record, or creating a new record.
|
|
|
|
*/
|
2022-02-11 13:10:53 +00:00
|
|
|
require: { [coldId: string]: CellValue } & { id?: number };
|
2022-07-27 19:29:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The values we will place in particular columns, either overwriting values in
|
|
|
|
* an existing record, or setting initial values in a new record.
|
|
|
|
*/
|
2022-02-11 13:10:53 +00:00
|
|
|
fields?: { [coldId: string]: CellValue };
|
|
|
|
}
|
|
|
|
|
2021-10-15 09:31:13 +00:00
|
|
|
/**
|
|
|
|
* JSON schema for the body of api /record PATCH endpoint
|
|
|
|
*/
|
|
|
|
export interface RecordsPatch {
|
|
|
|
records: [Record, ...Record[]]; // at least one record is required
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON schema for the body of api /record POST endpoint
|
|
|
|
*/
|
|
|
|
export interface RecordsPost {
|
|
|
|
records: [NewRecord, ...NewRecord[]]; // at least one record is required
|
|
|
|
}
|
2022-02-11 13:10:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON schema for the body of api /record PUT endpoint
|
|
|
|
*/
|
|
|
|
export interface RecordsPut {
|
|
|
|
records: [AddOrUpdateRecord, ...AddOrUpdateRecord[]]; // at least one record is required
|
|
|
|
}
|
2022-03-15 14:35:15 +00:00
|
|
|
|
|
|
|
export type RecordId = number;
|
|
|
|
|
2022-07-27 19:29:20 +00:00
|
|
|
/**
|
|
|
|
* The row id of a record, without any of its content.
|
|
|
|
*/
|
2022-03-15 14:35:15 +00:00
|
|
|
export interface MinimalRecord {
|
|
|
|
id: number
|
|
|
|
}
|
2022-10-20 19:24:14 +00:00
|
|
|
|
|
|
|
export interface ColumnsPost {
|
|
|
|
columns: [NewRecordWithStringId, ...NewRecordWithStringId[]]; // at least one column is required
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ColumnsPatch {
|
|
|
|
columns: [RecordWithStringId, ...RecordWithStringId[]]; // at least one column is required
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creating tables requires a list of columns.
|
|
|
|
* `fields` is not accepted because it's not generally sensible to set the metadata fields on new tables.
|
|
|
|
*/
|
|
|
|
export interface TablePost extends ColumnsPost {
|
|
|
|
id?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TablesPost {
|
|
|
|
tables: [TablePost, ...TablePost[]]; // at least one table is required
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TablesPatch {
|
|
|
|
tables: [RecordWithStringId, ...RecordWithStringId[]]; // at least one table is required
|
|
|
|
}
|