@gridsay/core holds what the table packages share: the error they reject with, the codes and messages of their own failures, the options they take, and the types of what the API accepts and returns. Every table package depends on it and installs it with itself. It is MIT-licensed and has no dependencies.
To use its types or constants directly, add it to your project:
npm install @gridsay/coreEvery failure a table package handles is a GridsayError. Show message; branch on code; log detail.
import { CONNECTION_FAILED_CODE, GridsayError } from '@gridsay/core'; export function describeFailure(error: unknown): string { if (!(error instanceof GridsayError)) throw error; if (error.code === 'rate_limited' && error.retryAfter !== undefined) return `${error.message} (wait ${error.retryAfter} s)`; if (error.code === CONNECTION_FAILED_CODE) return error.message; // detail is for you: log it, never show it. console.warn(error.code, error.status, error.detail); return error.message;}| Export | Kind | What it is |
|---|---|---|
GridsayError | class | The error every table package rejects with. See GridsayError. |
CONNECTION_FAILED, NOT_JSON, INVALID_ANSWER, UNAUTHENTICATED_USER | string constants | The sentences of the packages' own failures. See Codes. |
CONNECTION_FAILED_CODE, NOT_JSON_CODE, INVALID_ANSWER_CODE, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE, CANNOT_APPLY_CODE | string constants | The codes of the packages' own failures. |
RequestOptions, RequestHeaders | types | The options every table package takes. See Request options. |
ColumnContext, PromptOptions, PromptRequest, PromptData, GridState, GridSnapshot, GridColumnLimits, GridFeature, ColumnFilter, FilterValue, ColumnSort, Aggregation, AggregationFunction, Pivoting, Chart | types | The wire format. See Types. |
Do not import @gridsay/core/internal: it is for the table packages and can change in any release.
declare class GridsayError extends Error { readonly name: 'GridsayError'; readonly code?: string; readonly status?: number; readonly retryAfter?: number; readonly detail?: string; constructor(message: string, details?: { code?: string; status?: number; retryAfter?: number; detail?: string; cause?: unknown; });}| Field | Type | Meaning |
|---|---|---|
name | 'GridsayError' | Identifies the class. |
message | string | A sentence your user can read. A sentence from the API is kept as sent. |
code | string or undefined | An API error code or one of the codes below. Undefined when your own server answered with a message and no code. |
status | number or undefined | The HTTP status, when a response arrived. |
retryAfter | number or undefined | Seconds to wait: the body's retryAfter, else the Retry-After header. |
detail | string or undefined | The API's sentence for you. Never show it to users. |
cause | unknown | The original failure, when there was one. |
A 401 that names no code becomes unauthenticated_user; a 401 naming invalid_api_key keeps it.
These come from the browser, not from the API. Compare with the exported constants.
| Code | Constant | Message | When |
|---|---|---|---|
connection_failed | CONNECTION_FAILED_CODE | CONNECTION_FAILED: "The connection was interrupted. Try again." | The request failed, or reading the response was cut off. The question may still have been answered and charged. |
not_json | NOT_JSON_CODE | NOT_JSON: "The assistant couldn't respond. Try again." | The response is not JSON: often a wrong path, with status 404. |
invalid_answer | INVALID_ANSWER_CODE | INVALID_ANSWER: "The assistant couldn't complete your request. Try again." | The response is not a usable answer, or an error came with neither a sentence nor a code. |
unauthenticated_user | UNAUTHENTICATED_USER_CODE | UNAUTHENTICATED_USER: "Sign in to use the assistant." | getToken gave no token or threw, so nothing was sent; or a 401 named no code. Also the API's own code for a missing user token. |
unexpected_error | UNEXPECTED_ERROR_CODE | INVALID_ANSWER | Your headers function threw, so nothing was sent. On TanStack Table, also your table's own setup threw. cause holds what was thrown. |
cannot_apply | CANNOT_APPLY_CODE | The table package's own | A table package that applies answers itself could not apply one. The answer was already charged. |
Every table package takes these, beside its own options.
type RequestHeaders = Record<string, string>; type RequestOptions = { headers?: RequestHeaders | (() => RequestHeaders | Promise<RequestHeaders>); publishableKey?: string; getToken?: () => string | null | undefined | Promise<string | null | undefined>; additionalContext?: string; privateMode?: boolean; referenceId?: string;};| Option | Sent as | Meaning |
|---|---|---|
headers | Request headers | Extra headers, or a function called for each question. If it throws, nothing is sent: unexpected_error. |
publishableKey | x-api-key | A publishable key, for calls from the browser. Never a secret key. |
getToken | Authorization: Bearer … | Called for each question. No token, or a throw, sends nothing: unauthenticated_user. |
additionalContext | options.additionalContext | Notes for the assistant. |
privateMode | options.privateMode | See Private mode. |
referenceId | options.metadata.referenceId | Your id for the user, for usage reports. Not sign-in. |
publishableKey and getToken replace x-api-key and authorization set in headers only when those are written in lower case; written any other way, such as Authorization, both values are sent and the credentials fail, so leave those two headers out of headers. No option chooses a tier: the key does.
Types only: importing one gives no validation. They describe the data of an answer, not the whole response; the response envelope and the API's error codes are in Data Grid endpoint and Errors.
| Type | Describes |
|---|---|
PromptRequest | A request to /api/v1/datagrid/prompt: query, context, optional conversationId, options and grid. |
ColumnContext | One column inside context: field, and optional description, examples, type, allowedOperators, derivedFrom. Other properties are allowed. |
PromptOptions | options: privateMode, additionalContext, metadata.referenceId. |
GridSnapshot | grid: table, disabled, columns, state. |
GridFeature | A name in grid.disabled: filtering, sorting, grouping, aggregation, pivoting, selection, charts. |
GridColumnLimits | One column's restrictions in grid.columns. |
PromptData | An answer's data: GridState and conversationId. |
GridState | The whole state: select, filters, filterOperator, aggregation, sorting, grouping, pivoting, chart. |
ColumnFilter, FilterValue | One filter, and its value: text, number, boolean, or a list of text or of numbers. |
ColumnSort | A column and asc or desc. |
Aggregation, AggregationFunction | Column id to avg, sum, min, max or size. |
Pivoting | {}, or rows, columns and values. |
Chart | dimensions and values. |
Each field's rules and limits are on Data Grid endpoint.