mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) add grist.selectedTable.create/update/destroy/upsert to custom widget api
Summary: This makes an equivalent of the /records REST endpoint available within custom widgets. For simple operations, it is compatible with https://github.com/airtable/airtable.js/. About half of the diff is refactoring code from DocApi that implements /records using applyUserActions, to make that code available in the plugin api. Test Plan: added tests Reviewers: alexmojaki Reviewed By: alexmojaki Differential Revision: https://phab.getgrist.com/D3320
This commit is contained in:
44
app/plugin/TableOperations.ts
Normal file
44
app/plugin/TableOperations.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import * as Types from 'app/plugin/DocApiTypes';
|
||||
|
||||
/**
|
||||
* Offer CRUD-style operations on a table.
|
||||
*/
|
||||
export interface TableOperations {
|
||||
// Create a record or records.
|
||||
create(records: Types.NewRecord, options?: OpOptions): Promise<Types.MinimalRecord>;
|
||||
create(records: Types.NewRecord[], options?: OpOptions): Promise<Types.MinimalRecord[]>;
|
||||
|
||||
// Update a record or records.
|
||||
update(records: Types.Record|Types.Record[], options?: OpOptions): Promise<void>;
|
||||
|
||||
// Delete a record or records.
|
||||
destroy(recordId: Types.RecordId): Promise<Types.RecordId>;
|
||||
destroy(recordIds: Types.RecordId[]): Promise<Types.RecordId[]>;
|
||||
|
||||
// Add or update a record or records.
|
||||
upsert(records: Types.AddOrUpdateRecord|Types.AddOrUpdateRecord[],
|
||||
options?: UpsertOptions): Promise<void>;
|
||||
|
||||
// TODO: offer a way to query the table.
|
||||
// select(): Records;
|
||||
}
|
||||
|
||||
/**
|
||||
* General options for table operations.
|
||||
* By default, string field values will be parsed based on the column type.
|
||||
* This can be disabled.
|
||||
*/
|
||||
export interface OpOptions {
|
||||
parseStrings?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra options for upserts. By default, add and update are true,
|
||||
* onMany is first, and allowEmptyRequire is false.
|
||||
*/
|
||||
export interface UpsertOptions extends OpOptions {
|
||||
add?: boolean; // permit inserting a record
|
||||
update?: boolean; // permit updating a record
|
||||
onMany?: 'none' | 'first' | 'all'; // whether to update none, one, or all matching records
|
||||
allowEmptyRequire?: boolean; // allow "wildcard" operation
|
||||
}
|
||||
Reference in New Issue
Block a user