grist-widget-sdk 0.3.27 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +1 -1
- package/dist/app.cjs +1139 -4336
- package/dist/app.cjs.map +1 -1
- package/dist/app.d.cts +1 -3
- package/dist/app.d.ts +1 -3
- package/dist/app.js +3 -7
- package/dist/chunk-4ZGVKGDF.js +204 -0
- package/dist/chunk-4ZGVKGDF.js.map +1 -0
- package/dist/{chunk-YQNMIL33.js → chunk-B5ZZNLVS.js} +528 -181
- package/dist/chunk-B5ZZNLVS.js.map +1 -0
- package/dist/chunk-O7NY46QY.js +1830 -0
- package/dist/chunk-O7NY46QY.js.map +1 -0
- package/dist/{chunk-6Y2IONGJ.js → chunk-P6VTEKWO.js} +113 -14
- package/dist/chunk-P6VTEKWO.js.map +1 -0
- package/dist/emulator/testing.cjs +1504 -4822
- package/dist/emulator/testing.cjs.map +1 -1
- package/dist/emulator/testing.d.cts +3 -6
- package/dist/emulator/testing.d.ts +3 -6
- package/dist/emulator/testing.js +7 -20
- package/dist/emulator/testing.js.map +1 -1
- package/dist/emulator.cjs +59 -249
- package/dist/emulator.cjs.map +1 -1
- package/dist/emulator.d.cts +3 -5
- package/dist/emulator.d.ts +3 -5
- package/dist/emulator.js +5 -11
- package/dist/index.cjs +1373 -4859
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -260
- package/dist/index.d.ts +81 -260
- package/dist/index.js +8 -158
- package/dist/{inline-DpcT8tV9.d.ts → templates-CGmRIQBV.d.cts} +89 -35
- package/dist/{inline-C7DkvuET.d.cts → templates-Cq94qOcf.d.ts} +89 -35
- package/dist/{types-D3JxUCfL.d.cts → types-DBStn0Dk.d.cts} +2 -26
- package/dist/{types-D3JxUCfL.d.ts → types-DBStn0Dk.d.ts} +2 -26
- package/dist/use-grist-BK0eke9K.d.cts +358 -0
- package/dist/use-grist-C5DMZ3wU.d.ts +358 -0
- package/package.json +8 -37
- package/dist/advanced.cjs +0 -2799
- package/dist/advanced.cjs.map +0 -1
- package/dist/advanced.d.cts +0 -822
- package/dist/advanced.d.ts +0 -822
- package/dist/advanced.js +0 -872
- package/dist/advanced.js.map +0 -1
- package/dist/chunk-22U7WAY3.js +0 -463
- package/dist/chunk-22U7WAY3.js.map +0 -1
- package/dist/chunk-64SVRWW7.js +0 -758
- package/dist/chunk-64SVRWW7.js.map +0 -1
- package/dist/chunk-6Y2IONGJ.js.map +0 -1
- package/dist/chunk-B4AKVSWV.js +0 -2362
- package/dist/chunk-B4AKVSWV.js.map +0 -1
- package/dist/chunk-ELGVOHFD.js +0 -32
- package/dist/chunk-ELGVOHFD.js.map +0 -1
- package/dist/chunk-GTTD5HPO.js +0 -36
- package/dist/chunk-GTTD5HPO.js.map +0 -1
- package/dist/chunk-NO6FYX33.js +0 -2084
- package/dist/chunk-NO6FYX33.js.map +0 -1
- package/dist/chunk-OPTOYD2Y.js +0 -277
- package/dist/chunk-OPTOYD2Y.js.map +0 -1
- package/dist/chunk-PM3B4WYV.js +0 -12
- package/dist/chunk-PM3B4WYV.js.map +0 -1
- package/dist/chunk-REV5AUXD.js +0 -25
- package/dist/chunk-REV5AUXD.js.map +0 -1
- package/dist/chunk-YQNMIL33.js.map +0 -1
- package/dist/create-grist-emulator-BCqp1BF9.d.ts +0 -81
- package/dist/create-grist-emulator-DBM8OSIR.d.cts +0 -81
- package/dist/emulator/devtools.cjs +0 -1404
- package/dist/emulator/devtools.cjs.map +0 -1
- package/dist/emulator/devtools.d.cts +0 -48
- package/dist/emulator/devtools.d.ts +0 -48
- package/dist/emulator/devtools.js +0 -506
- package/dist/emulator/devtools.js.map +0 -1
- package/dist/emulator/transports.cjs +0 -1132
- package/dist/emulator/transports.cjs.map +0 -1
- package/dist/emulator/transports.d.cts +0 -38
- package/dist/emulator/transports.d.ts +0 -38
- package/dist/emulator/transports.js +0 -12
- package/dist/emulator/transports.js.map +0 -1
- package/dist/templates-8k2LKoO-.d.cts +0 -24
- package/dist/templates-DIwi_mvI.d.ts +0 -24
- package/dist/use-grist-reads-DUMvJgV7.d.ts +0 -480
- package/dist/use-grist-reads-DpjVuI0H.d.cts +0 -480
- package/dist/use-grist-types-DdOLEJXN.d.cts +0 -499
- package/dist/use-grist-types-kwxoFeub.d.ts +0 -499
- package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.cts +0 -43
- package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.ts +0 -43
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
import { c as GristReplicaColumn, G as GristRowRecord, s as GristDocApi, n as GristRequiredAccess, r as GristColumnsToMap, d as GristWidgetColumnMap, i as GristReadyOptions } from './types-D3JxUCfL.cjs';
|
|
2
|
-
import { z, ZodType } from 'zod';
|
|
3
|
-
|
|
4
|
-
type GristSafeParseIssueCode = "grist_error" | "invalid_format" | "type_mismatch" | "helper_mismatch" | "zod_error";
|
|
5
|
-
type GristSafeParseIssue = {
|
|
6
|
-
code: GristSafeParseIssueCode;
|
|
7
|
-
message: string;
|
|
8
|
-
};
|
|
9
|
-
type GristSafeRefValue = {
|
|
10
|
-
rowId: number;
|
|
11
|
-
display?: string | null;
|
|
12
|
-
};
|
|
13
|
-
type GristSafeRefListValue = {
|
|
14
|
-
rowIds: number[];
|
|
15
|
-
displays?: string[];
|
|
16
|
-
};
|
|
17
|
-
declare const gristSafeRefValueSchema: z.ZodObject<{
|
|
18
|
-
rowId: z.ZodNumber;
|
|
19
|
-
display: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
-
}, z.core.$strip>;
|
|
21
|
-
declare const gristSafeRefListValueSchema: z.ZodObject<{
|
|
22
|
-
rowIds: z.ZodArray<z.ZodNumber>;
|
|
23
|
-
displays: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
-
}, z.core.$strip>;
|
|
25
|
-
declare const gristCellValueSchema: z.ZodUnion<readonly [z.ZodNull, z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate, z.ZodArray<z.ZodUnknown>, z.ZodObject<{
|
|
26
|
-
rowId: z.ZodNumber;
|
|
27
|
-
display: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
29
|
-
rowIds: z.ZodArray<z.ZodNumber>;
|
|
30
|
-
displays: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
31
|
-
}, z.core.$strip>]>;
|
|
32
|
-
type GristCellValue = z.infer<typeof gristCellValueSchema>;
|
|
33
|
-
type GristSafeParseCellResult<TValue = unknown> = {
|
|
34
|
-
ok: boolean;
|
|
35
|
-
typedValue: TValue | null;
|
|
36
|
-
displayValue: unknown;
|
|
37
|
-
raw: unknown;
|
|
38
|
-
issues: GristSafeParseIssue[];
|
|
39
|
-
};
|
|
40
|
-
type RefMode = "id" | "detailed";
|
|
41
|
-
type SafeParseGristValuesOptions<TValue = unknown> = {
|
|
42
|
-
values: readonly unknown[];
|
|
43
|
-
column?: GristReplicaColumn;
|
|
44
|
-
helperValues?: readonly unknown[];
|
|
45
|
-
schema?: ZodType<TValue>;
|
|
46
|
-
fallbackUntypedToString?: boolean;
|
|
47
|
-
refMode?: RefMode;
|
|
48
|
-
};
|
|
49
|
-
type SafeParseGristTableDataOptions = {
|
|
50
|
-
columns?: Record<string, GristReplicaColumn>;
|
|
51
|
-
displayHelpersByRef?: Record<string, string>;
|
|
52
|
-
order?: "none" | "id" | "grist";
|
|
53
|
-
fallbackUntypedToString?: boolean;
|
|
54
|
-
refMode?: RefMode;
|
|
55
|
-
};
|
|
56
|
-
type GristSafeTableCellIssue = GristSafeParseIssue & {
|
|
57
|
-
rowIndex: number;
|
|
58
|
-
colId: string;
|
|
59
|
-
};
|
|
60
|
-
type GristSafeChoiceTokenMeta = {
|
|
61
|
-
value: string;
|
|
62
|
-
label: string;
|
|
63
|
-
fillColor?: string;
|
|
64
|
-
textColor?: string;
|
|
65
|
-
valid: boolean;
|
|
66
|
-
};
|
|
67
|
-
type GristSafeTableCellMeta = {
|
|
68
|
-
rowIndex: number;
|
|
69
|
-
colId: string;
|
|
70
|
-
ok: boolean;
|
|
71
|
-
issues: GristSafeParseIssue[];
|
|
72
|
-
choiceTokens?: GristSafeChoiceTokenMeta[];
|
|
73
|
-
};
|
|
74
|
-
type SafeParseGristTableDataResult<TRow extends Record<string, unknown> = Record<string, unknown>> = {
|
|
75
|
-
rows: GristRowRecord<TRow>[];
|
|
76
|
-
cellIssues: GristSafeTableCellIssue[];
|
|
77
|
-
cellMeta: GristSafeTableCellMeta[];
|
|
78
|
-
cellMetaByKey: Record<string, GristSafeTableCellMeta>;
|
|
79
|
-
cellResultsByColumn: Record<string, GristSafeParseCellResult[]>;
|
|
80
|
-
};
|
|
81
|
-
/** Maps `Ref:*` / `RefList:*` column ids to their paired `gristHelper_*` column id (same rules as safe-parse). */
|
|
82
|
-
declare function inferDisplayHelpersByRef(columns: Record<string, GristReplicaColumn>): Record<string, string>;
|
|
83
|
-
declare function safeParseGristValues<TValue = unknown>(options: SafeParseGristValuesOptions<TValue>): GristSafeParseCellResult<TValue>[];
|
|
84
|
-
declare function safeParseGristTableData<TRow extends Record<string, unknown> = Record<string, unknown>>(data: GristColumnarTable, options?: SafeParseGristTableDataOptions): SafeParseGristTableDataResult<TRow>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Column-oriented table payload from `grist.docApi.fetchTable`.
|
|
88
|
-
*/
|
|
89
|
-
type GristColumnarTable = Record<string, unknown[]>;
|
|
90
|
-
type GristTableRowsOrder = "none" | "id" | "grist";
|
|
91
|
-
type FetchGristTableRowsOptions = {
|
|
92
|
-
/** Optional schema metadata map to decode cells (except `id`) with `decodeGristValue`. */
|
|
93
|
-
columns?: Record<string, GristReplicaColumn>;
|
|
94
|
-
/**
|
|
95
|
-
* Row ordering strategy.
|
|
96
|
-
* - `grist` (default): `manualSort` ascending when present, fallback `id`.
|
|
97
|
-
* - `id`: numeric `id` ascending.
|
|
98
|
-
* - `none`: preserve raw `fetchTable` row order.
|
|
99
|
-
*/
|
|
100
|
-
order?: GristTableRowsOrder;
|
|
101
|
-
/**
|
|
102
|
-
* Enable safe parsing with issue reporting.
|
|
103
|
-
* - `true`: use safe parsing with defaults.
|
|
104
|
-
* - object: pass safe-parse options (`displayHelpersByRef`, `refMode`, ...).
|
|
105
|
-
*/
|
|
106
|
-
safeParse?: boolean | Omit<SafeParseGristTableDataOptions, "columns" | "order">;
|
|
107
|
-
/** Optional callback fired with per-cell parse issues when `safeParse` is enabled. */
|
|
108
|
-
onSafeParseIssues?: (issues: GristSafeTableCellIssue[]) => void;
|
|
109
|
-
/** Optional callback fired with enriched per-cell safe-parse metadata. */
|
|
110
|
-
onSafeParseCellMeta?: (meta: GristSafeTableCellMeta[]) => void;
|
|
111
|
-
/** Optional callback fired with keyed per-cell metadata (`${rowId}:${colId}`). */
|
|
112
|
-
onSafeParseCellMetaByKey?: (metaByKey: Record<string, GristSafeTableCellMeta>) => void;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Project safe-parse rows to UI display rows by taking each cell's `displayValue`.
|
|
116
|
-
* Useful for grids that render human-friendly values while keeping safe-cell
|
|
117
|
-
* objects available for logic and metadata.
|
|
118
|
-
*/
|
|
119
|
-
declare function safeParseRowsToDisplayRows(rows: ReadonlyArray<Record<string, unknown>>): GristRowRecord<Record<string, unknown>>[];
|
|
120
|
-
/** Row count from columnar `fetchTable` data (prefers `id` column length). */
|
|
121
|
-
declare function computeRowCount(data: Record<string, unknown[]>): number;
|
|
122
|
-
/**
|
|
123
|
-
* Decode columnar `fetchTable` into replica row objects (same convention as the playground grid).
|
|
124
|
-
*/
|
|
125
|
-
declare function decodeColumnarToReplicaRows(data: GristColumnarTable, columnIds: string[], columns: Record<string, GristReplicaColumn>, maxRows?: number): GristRowRecord[];
|
|
126
|
-
/** Turn `fetchTable` output into row objects (order follows the `id` column). */
|
|
127
|
-
declare function tableDataToRows<T = Record<string, unknown>>(data: GristColumnarTable): GristRowRecord<T>[];
|
|
128
|
-
/**
|
|
129
|
-
* Sort rows by Grist's display order: `manualSort` ascending when present on
|
|
130
|
-
* any row, otherwise numeric `id` ascending.
|
|
131
|
-
*/
|
|
132
|
-
declare function sortRowsByGristOrder<T = Record<string, unknown>>(rows: readonly GristRowRecord<T>[]): GristRowRecord<T>[];
|
|
133
|
-
/** Row index where `id` matches `rowId`, or `null`. */
|
|
134
|
-
declare function findRowIndexById(data: GristColumnarTable, rowId: number | string): number | null;
|
|
135
|
-
/** Single row at `index`, or `null` if out of range. */
|
|
136
|
-
declare function rowAtIndex<T = Record<string, unknown>>(data: GristColumnarTable, index: number): GristRowRecord<T> | null;
|
|
137
|
-
/**
|
|
138
|
-
* Fetch a single row from any table by id. Convenience around
|
|
139
|
-
* `docApi.fetchTable` + {@link findRowIndexById} + {@link rowAtIndex}.
|
|
140
|
-
*/
|
|
141
|
-
declare function fetchGristRow<T = Record<string, unknown>>(docApi: GristDocApi, tableId: string, rowId: number): Promise<GristRowRecord<T> | null>;
|
|
142
|
-
/**
|
|
143
|
-
* Same row materialization as {@link fetchGristTableRows} after `fetchTable`
|
|
144
|
-
* returns columnar data. Hosts that already have columnar data (e.g. the
|
|
145
|
-
* emulator building from in-memory rows) can use this and skip `docApi.fetchTable`.
|
|
146
|
-
*/
|
|
147
|
-
declare function materializeGristRowsFromColumnar<T extends Record<string, unknown> = Record<string, unknown>>(data: GristColumnarTable, options?: FetchGristTableRowsOptions): GristRowRecord<T>[];
|
|
148
|
-
/**
|
|
149
|
-
* Fetch a table and return rows as objects, optionally decoded from schema and sorted.
|
|
150
|
-
*/
|
|
151
|
-
declare function fetchGristTableRows<T extends Record<string, unknown> = Record<string, unknown>>(docApi: GristDocApi, tableId: string, options: FetchGristTableRowsOptions & {
|
|
152
|
-
safeParse: true | Omit<SafeParseGristTableDataOptions, "columns" | "order">;
|
|
153
|
-
}): Promise<GristRowRecord<{
|
|
154
|
-
[K in keyof T]: GristSafeParseCellResult<T[K]> | null;
|
|
155
|
-
}>[]>;
|
|
156
|
-
declare function fetchGristTableRows<T extends Record<string, unknown> = Record<string, unknown>>(docApi: GristDocApi, tableId: string, options?: FetchGristTableRowsOptions): Promise<GristRowRecord<T>[]>;
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Grist `docApi.applyUserActions` payloads are arrays of user-action tuples.
|
|
160
|
-
* @see https://support.getgrist.com/code/interfaces/grist_plugin_api.GristDocAPI/#applyuseractions
|
|
161
|
-
*/
|
|
162
|
-
type GristUserActionTuple = unknown[];
|
|
163
|
-
/** `["UpdateRecord", tableId, rowId, { col: value, ... }]` */
|
|
164
|
-
declare function gristUpdateRecordAction(tableId: string, rowId: number, patch: Record<string, unknown>): GristUserActionTuple;
|
|
165
|
-
/** `["AddRecord", tableId, null, { col: value, ... }]` */
|
|
166
|
-
declare function gristAddRecordAction(tableId: string, values: Record<string, unknown>): GristUserActionTuple;
|
|
167
|
-
/** `["RemoveRecord", tableId, rowId]` */
|
|
168
|
-
declare function gristRemoveRecordAction(tableId: string, rowId: number): GristUserActionTuple;
|
|
169
|
-
/** `["BulkUpdateRecord", tableId, rowIds, { col: value[], ... }]` — column arrays must align with `rowIds`. */
|
|
170
|
-
declare function gristBulkUpdateRecordAction(tableId: string, rowIds: number[], columnarPatch: Record<string, unknown[]>): GristUserActionTuple;
|
|
171
|
-
/**
|
|
172
|
-
* `["BulkAddRecord", tableId, rowIds | nullArray, { col: value[], ... }]`.
|
|
173
|
-
* Pass `null` (or omit) for `rowIds` to let Grist allocate ids; in user-action
|
|
174
|
-
* format Grist expects an array of nulls of the same length as the value arrays.
|
|
175
|
-
*/
|
|
176
|
-
declare function gristBulkAddRecordAction(tableId: string, values: Record<string, unknown[]>, rowIds?: Array<number | null>): GristUserActionTuple;
|
|
177
|
-
/** `["BulkRemoveRecord", tableId, rowIds]` */
|
|
178
|
-
declare function gristBulkRemoveRecordAction(tableId: string, rowIds: number[]): GristUserActionTuple;
|
|
179
|
-
/** `["AddColumn", tableId, colId, colInfo]` — `colInfo` shape depends on Grist version / column type. */
|
|
180
|
-
declare function gristAddColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
181
|
-
/** `["AddVisibleColumn", tableId, colId, colInfo]` — like `AddColumn` but also adds the column to the current view section. */
|
|
182
|
-
declare function gristAddVisibleColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
183
|
-
/** `["RenameColumn", tableId, colId, newColId]` */
|
|
184
|
-
declare function gristRenameColumnAction(tableId: string, colId: string, newColId: string): GristUserActionTuple;
|
|
185
|
-
/** `["ModifyColumn", tableId, colId, colInfo]` */
|
|
186
|
-
declare function gristModifyColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
187
|
-
/** `["RemoveColumn", tableId, colId]` */
|
|
188
|
-
declare function gristRemoveColumnAction(tableId: string, colId: string): GristUserActionTuple;
|
|
189
|
-
/** `["AddTable", tableId, tableInfo]` */
|
|
190
|
-
declare function gristAddTableAction(tableId: string, tableInfo: Record<string, unknown>): GristUserActionTuple;
|
|
191
|
-
/** `["RenameTable", tableId, newTableId]` */
|
|
192
|
-
declare function gristRenameTableAction(tableId: string, newTableId: string): GristUserActionTuple;
|
|
193
|
-
/** `["RemoveTable", tableId]` */
|
|
194
|
-
declare function gristRemoveTableAction(tableId: string): GristUserActionTuple;
|
|
195
|
-
/** `["DuplicateTable", tableId, newTableId, options?]` */
|
|
196
|
-
declare function gristDuplicateTableAction(tableId: string, newTableId: string, options?: Record<string, unknown>): GristUserActionTuple;
|
|
197
|
-
/** `["ReplaceTableData", tableId, rowIds, columnarData]` */
|
|
198
|
-
declare function gristReplaceTableDataAction(tableId: string, rowIds: Array<number | null>, columnarData: Record<string, unknown[]>): GristUserActionTuple;
|
|
199
|
-
/** `["SetDocumentInfo", info]` */
|
|
200
|
-
declare function gristSetDocumentInfoAction(info: Record<string, unknown>): GristUserActionTuple;
|
|
201
|
-
|
|
202
|
-
type GristColumnLike = {
|
|
203
|
-
formula?: string;
|
|
204
|
-
};
|
|
205
|
-
type GristNoiseColumnsOptions = {
|
|
206
|
-
excludeId?: boolean;
|
|
207
|
-
excludeGristHelpers?: boolean;
|
|
208
|
-
excludeLoggingColumns?: boolean;
|
|
209
|
-
/**
|
|
210
|
-
* When `true`, treat Grist's `manualSort` column as noise (omit from filtered replicas).
|
|
211
|
-
* Default `false` — `manualSort` is kept unless you opt in.
|
|
212
|
-
*/
|
|
213
|
-
excludeManualSort?: boolean;
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Grist-centric "technical column" detection used by document hooks and widgets.
|
|
217
|
-
*
|
|
218
|
-
* - `id` (when {@link GristNoiseColumnsOptions.excludeId} is true — default)
|
|
219
|
-
* - `manualSort` (only when {@link GristNoiseColumnsOptions.excludeManualSort} is true)
|
|
220
|
-
* - `gristHelper_*` (when `excludeGristHelpers` is true — default)
|
|
221
|
-
* - trigger/logging formulas (`NOW()`, `user.*`) (when `excludeLoggingColumns` is true — default)
|
|
222
|
-
*/
|
|
223
|
-
declare function isGristNoiseColumn(colId: string, col?: GristColumnLike, options?: GristNoiseColumnsOptions): boolean;
|
|
224
|
-
|
|
225
|
-
type GristAccessToken = {
|
|
226
|
-
token: string;
|
|
227
|
-
baseUrl: string;
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Returns an access token suitable for calling Grist's REST API directly.
|
|
231
|
-
* Tokens are short-lived; results are cached briefly and coalesced per readOnly flag.
|
|
232
|
-
*/
|
|
233
|
-
declare function getGristAccessToken(docApi: GristDocApi, options?: {
|
|
234
|
-
readOnly?: boolean;
|
|
235
|
-
}): Promise<GristAccessToken>;
|
|
236
|
-
/**
|
|
237
|
-
* `fetch()` against Grist's REST API with the doc access token attached.
|
|
238
|
-
*/
|
|
239
|
-
declare function fetchWithGristAuth(docApi: GristDocApi, path: string, init?: RequestInit & {
|
|
240
|
-
readOnly?: boolean;
|
|
241
|
-
}): Promise<Response>;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Pure type contracts for the handshake / synchronization state machine.
|
|
245
|
-
*
|
|
246
|
-
* The machine models five orthogonal axes that together describe the widget's
|
|
247
|
-
* relationship with the Grist host:
|
|
248
|
-
*
|
|
249
|
-
* 1. `LIFECYCLE` — protocol handshake (one-shot via `grist.ready`).
|
|
250
|
-
* 2. `LINK` — RPC channel health (continuous, post-online).
|
|
251
|
-
* 3. `AUTHZ` — effective access level granted by the host.
|
|
252
|
-
* 4. `CONFIG` — column mapping contract with the end-user.
|
|
253
|
-
* 5. `SYNC` — freshness of each event stream and ancillary RPCs.
|
|
254
|
-
*
|
|
255
|
-
* The legacy public `status` ("booting" / "ready" / "unavailable" / "error")
|
|
256
|
-
* is a **pure projection** of the snapshot, computed in `./derive.ts`.
|
|
257
|
-
*
|
|
258
|
-
* No runtime side effects in this file — types only.
|
|
259
|
-
*/
|
|
260
|
-
|
|
261
|
-
/** Monotone counter bumped on reload / restart / link recovery / access widening. */
|
|
262
|
-
type GristGeneration = number & {
|
|
263
|
-
readonly __brand: "GristGeneration";
|
|
264
|
-
};
|
|
265
|
-
type GristLifecyclePhase = "idle" | "detecting" | "negotiating" | "online" | "terminated";
|
|
266
|
-
type GristTerminationReason = {
|
|
267
|
-
kind: "script_timeout";
|
|
268
|
-
attempts: number;
|
|
269
|
-
} | {
|
|
270
|
-
kind: "not_embedded";
|
|
271
|
-
} | {
|
|
272
|
-
kind: "ready_failed";
|
|
273
|
-
message: string;
|
|
274
|
-
} | {
|
|
275
|
-
kind: "ready_timeout";
|
|
276
|
-
afterMs: number;
|
|
277
|
-
} | {
|
|
278
|
-
kind: "host_rejected";
|
|
279
|
-
message: string;
|
|
280
|
-
} | {
|
|
281
|
-
kind: "manual_terminate";
|
|
282
|
-
};
|
|
283
|
-
type GristLifecycle = {
|
|
284
|
-
phase: "idle";
|
|
285
|
-
} | {
|
|
286
|
-
phase: "detecting";
|
|
287
|
-
attempts: number;
|
|
288
|
-
startedAtMs: number;
|
|
289
|
-
} | {
|
|
290
|
-
phase: "negotiating";
|
|
291
|
-
access: GristRequiredAccess;
|
|
292
|
-
startedAtMs: number;
|
|
293
|
-
} | {
|
|
294
|
-
phase: "online";
|
|
295
|
-
sinceMs: number;
|
|
296
|
-
declaredAccess: GristRequiredAccess;
|
|
297
|
-
} | {
|
|
298
|
-
phase: "terminated";
|
|
299
|
-
reason: GristTerminationReason;
|
|
300
|
-
atMs: number;
|
|
301
|
-
};
|
|
302
|
-
type GristLinkState = "connected" | "stale" | "lost";
|
|
303
|
-
type GristLink = {
|
|
304
|
-
state: GristLinkState;
|
|
305
|
-
/** ms timestamp of last successful RPC (or heartbeat). `null` before any. */
|
|
306
|
-
lastSuccessMs: number | null;
|
|
307
|
-
/** Consecutive RPC failures since the last success. */
|
|
308
|
-
missedPings: number;
|
|
309
|
-
};
|
|
310
|
-
type GristAuthz = {
|
|
311
|
-
state: "pending";
|
|
312
|
-
declared: GristRequiredAccess;
|
|
313
|
-
} | {
|
|
314
|
-
state: "granted";
|
|
315
|
-
/** Effective level granted by the host. May differ from `declared`. */
|
|
316
|
-
level: GristRequiredAccess;
|
|
317
|
-
declared: GristRequiredAccess;
|
|
318
|
-
/** True if granted level >= a previously granted level for the same widget. */
|
|
319
|
-
widened: boolean;
|
|
320
|
-
} | {
|
|
321
|
-
state: "denied";
|
|
322
|
-
declared: GristRequiredAccess;
|
|
323
|
-
message?: string;
|
|
324
|
-
};
|
|
325
|
-
/**
|
|
326
|
-
* Source that produced a mapping payload, used for deterministic merge by
|
|
327
|
-
* {@link MappingResolver} (see `./mapping-resolver.ts`).
|
|
328
|
-
*/
|
|
329
|
-
type GristMappingSource = "section_api" | "stream_record" | "stream_records" | "stream_new_record";
|
|
330
|
-
type GristMappingComplete = {
|
|
331
|
-
state: "complete";
|
|
332
|
-
declared: GristColumnsToMap;
|
|
333
|
-
mappings: GristWidgetColumnMap;
|
|
334
|
-
/** `"merged"` is used internally when multiple sources contributed. */
|
|
335
|
-
source: GristMappingSource | "merged";
|
|
336
|
-
reportedAtMs: number;
|
|
337
|
-
};
|
|
338
|
-
type GristMappingIncomplete = {
|
|
339
|
-
state: "incomplete";
|
|
340
|
-
declared: GristColumnsToMap;
|
|
341
|
-
mappings: GristWidgetColumnMap;
|
|
342
|
-
missing: readonly string[];
|
|
343
|
-
emptyMultiples: readonly string[];
|
|
344
|
-
source: GristMappingSource | "merged";
|
|
345
|
-
reportedAtMs: number;
|
|
346
|
-
};
|
|
347
|
-
type GristMappingState =
|
|
348
|
-
/** Widget did not declare any `columns` in `grist.ready`. */
|
|
349
|
-
{
|
|
350
|
-
state: "not_declared";
|
|
351
|
-
}
|
|
352
|
-
/** Columns declared but no host report yet received. */
|
|
353
|
-
| {
|
|
354
|
-
state: "pending";
|
|
355
|
-
declared: GristColumnsToMap;
|
|
356
|
-
declaredAtMs: number;
|
|
357
|
-
} | GristMappingIncomplete | GristMappingComplete
|
|
358
|
-
/** User just modified the mapping; previous payload preserved to avoid UI flicker. */
|
|
359
|
-
| {
|
|
360
|
-
state: "invalidating";
|
|
361
|
-
previous: GristMappingIncomplete | GristMappingComplete;
|
|
362
|
-
sinceMs: number;
|
|
363
|
-
}
|
|
364
|
-
/** Declared but no host report after a timeout. Soft state — payload may still arrive. */
|
|
365
|
-
| {
|
|
366
|
-
state: "unreported";
|
|
367
|
-
declared: GristColumnsToMap;
|
|
368
|
-
afterMs: number;
|
|
369
|
-
};
|
|
370
|
-
type GristConfig = {
|
|
371
|
-
mappings: GristMappingState;
|
|
372
|
-
};
|
|
373
|
-
type GristStreamFreshness = {
|
|
374
|
-
state: "cold";
|
|
375
|
-
} | {
|
|
376
|
-
state: "warming";
|
|
377
|
-
sinceMs: number;
|
|
378
|
-
} | {
|
|
379
|
-
state: "hot";
|
|
380
|
-
lastEventMs: number;
|
|
381
|
-
generation: GristGeneration;
|
|
382
|
-
payloadHash: string;
|
|
383
|
-
} | {
|
|
384
|
-
state: "stale";
|
|
385
|
-
lastEventMs: number;
|
|
386
|
-
reason: "link_lost" | "tab_hidden" | "host_quiet";
|
|
387
|
-
};
|
|
388
|
-
type GristCurrentTableState = {
|
|
389
|
-
state: "unknown";
|
|
390
|
-
} | {
|
|
391
|
-
state: "known";
|
|
392
|
-
tableId: string;
|
|
393
|
-
refreshing: boolean;
|
|
394
|
-
}
|
|
395
|
-
/** Local error (e.g. `selectedTable.getTableId()` rejected) — does NOT propagate to global status. */
|
|
396
|
-
| {
|
|
397
|
-
state: "errored";
|
|
398
|
-
message: string;
|
|
399
|
-
sinceMs: number;
|
|
400
|
-
};
|
|
401
|
-
type GristSync = {
|
|
402
|
-
record: GristStreamFreshness;
|
|
403
|
-
records: GristStreamFreshness;
|
|
404
|
-
options: GristStreamFreshness;
|
|
405
|
-
newRecord: GristStreamFreshness;
|
|
406
|
-
currentTable: GristCurrentTableState;
|
|
407
|
-
};
|
|
408
|
-
type GristWidgetSnapshot = {
|
|
409
|
-
generation: GristGeneration;
|
|
410
|
-
lifecycle: GristLifecycle;
|
|
411
|
-
link: GristLink;
|
|
412
|
-
authz: GristAuthz;
|
|
413
|
-
config: GristConfig;
|
|
414
|
-
sync: GristSync;
|
|
415
|
-
};
|
|
416
|
-
/** Canonical 4-state status — projected from the handshake snapshot. */
|
|
417
|
-
type GristWidgetStatus = "booting" | "ready" | "unavailable" | "error";
|
|
418
|
-
/**
|
|
419
|
-
* Pre-computed booleans that widget code should consume directly instead of
|
|
420
|
-
* re-deriving from `status` + mapping flags + writes flags.
|
|
421
|
-
*
|
|
422
|
-
* Every field is a **pure function of the snapshot** and is referentially
|
|
423
|
-
* stable across renders that don't change the snapshot's relevant slices.
|
|
424
|
-
*/
|
|
425
|
-
type GristCapabilities = {
|
|
426
|
-
/** `lifecycle.online` + `link != lost` + `authz.state === "granted"` with read or higher. */
|
|
427
|
-
canRead: boolean;
|
|
428
|
-
/** `canRead` + (`mappings.state` is `complete` or `not_declared`). */
|
|
429
|
-
canRender: boolean;
|
|
430
|
-
/** `canRender` + `authz.level === "full"`. Required before any write. */
|
|
431
|
-
canWriteRecords: boolean;
|
|
432
|
-
/** `canWriteRecords` + `sync.currentTable.state === "known"`. */
|
|
433
|
-
canWriteSchema: boolean;
|
|
434
|
-
/** `canRead` + `link === "connected"`. */
|
|
435
|
-
canFetchTable: boolean;
|
|
436
|
-
/** `canRead` + `sync.record.state === "hot"` + mappings not invalidating. */
|
|
437
|
-
hasFreshSelection: boolean;
|
|
438
|
-
/** `mappings.state === "complete" || "not_declared"`. */
|
|
439
|
-
hasUsableMappings: boolean;
|
|
440
|
-
/** Logical column names still missing from user mapping (incomplete only). */
|
|
441
|
-
missingMappings: readonly string[];
|
|
442
|
-
/** `allowMultiple` columns mapped to `[]` (incomplete only). */
|
|
443
|
-
emptyMultipleMappings: readonly string[];
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
type UseGristCoreOptions = GristReadyOptions & {
|
|
447
|
-
availabilityMaxAttempts?: number;
|
|
448
|
-
availabilityIntervalMs?: number;
|
|
449
|
-
logWhenNotEmbedded?: boolean;
|
|
450
|
-
};
|
|
451
|
-
type UseGristCoreResult = {
|
|
452
|
-
status: GristWidgetStatus;
|
|
453
|
-
isAvailable: boolean | null;
|
|
454
|
-
isReady: boolean;
|
|
455
|
-
error: string | null;
|
|
456
|
-
docApi: GristDocApi | null;
|
|
457
|
-
/** Derived from the handshake snapshot — same values as `useGristCapabilities()` on `/advanced`. */
|
|
458
|
-
capabilities: GristCapabilities;
|
|
459
|
-
reload: () => Promise<void>;
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
type ListTablesOptions = {
|
|
463
|
-
/** When true, include system tables (prefixed with `_grist` or `GristHidden_`). Default: false. */
|
|
464
|
-
includeSystem?: boolean;
|
|
465
|
-
};
|
|
466
|
-
type GristColumnInfo = {
|
|
467
|
-
colId: string;
|
|
468
|
-
type?: string;
|
|
469
|
-
label?: string;
|
|
470
|
-
isFormula?: boolean;
|
|
471
|
-
formula?: string;
|
|
472
|
-
description?: string;
|
|
473
|
-
};
|
|
474
|
-
type ListColumnsOptions = GristNoiseColumnsOptions & {
|
|
475
|
-
/** When true, include system tables' columns. Default: false. */
|
|
476
|
-
includeSystem?: boolean;
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
export { inferDisplayHelpersByRef as $, findRowIndexById as A, getGristAccessToken as B, gristAddColumnAction as C, gristAddRecordAction as D, gristAddTableAction as E, gristAddVisibleColumnAction as H, gristBulkAddRecordAction as I, gristBulkRemoveRecordAction as J, gristBulkUpdateRecordAction as K, gristCellValueSchema as M, gristDuplicateTableAction as N, gristModifyColumnAction as O, gristRemoveColumnAction as P, gristRemoveRecordAction as Q, gristRemoveTableAction as R, gristRenameColumnAction as T, gristRenameTableAction as V, gristReplaceTableDataAction as W, gristSafeRefListValueSchema as X, gristSafeRefValueSchema as Y, gristSetDocumentInfoAction as Z, gristUpdateRecordAction as _, isGristNoiseColumn as a0, materializeGristRowsFromColumnar as a1, rowAtIndex as a2, safeParseGristTableData as a3, safeParseGristValues as a4, safeParseRowsToDisplayRows as a5, sortRowsByGristOrder as a6, tableDataToRows as a7, computeRowCount as v, decodeColumnarToReplicaRows as w, fetchGristRow as x, fetchGristTableRows as y, fetchWithGristAuth as z };
|
|
480
|
-
export type { FetchGristTableRowsOptions as F, GristWidgetSnapshot as G, ListColumnsOptions as L, SafeParseGristTableDataOptions as S, UseGristCoreOptions as U, GristNoiseColumnsOptions as a, GristTerminationReason as a8, GristGeneration as a9, GristMappingSource as aa, GristAuthz as ab, GristConfig as ac, GristCurrentTableState as ad, GristLifecycle as ae, GristLifecyclePhase as af, GristLink as ag, GristLinkState as ah, GristMappingComplete as ai, GristMappingIncomplete as aj, GristMappingState as ak, GristStreamFreshness as al, GristSync as am, GristAccessToken as b, GristCapabilities as c, GristCellValue as d, GristColumnInfo as e, GristColumnLike as f, GristColumnarTable as g, GristSafeParseCellResult as h, GristSafeParseIssue as i, GristSafeParseIssueCode as j, GristSafeRefListValue as k, GristSafeRefValue as l, GristSafeTableCellIssue as m, GristSafeTableCellMeta as n, GristTableRowsOrder as o, GristUserActionTuple as p, GristWidgetStatus as q, ListTablesOptions as r, SafeParseGristTableDataResult as s, SafeParseGristValuesOptions as t, UseGristCoreResult as u };
|