refine-apito
Version:
A data provider for Refine that connects to Apito - a headless CMS and backend builder.
87 lines (85 loc) • 6.53 kB
text/typescript
/**
* Apito model naming aligned with `open-core/utility/apito_naming.go`.
* Store canonical model ids as snake_case (e.g. `food_order`); derive GraphQL names with pure string ops.
*/
/**
* Normalizes admin input to canonical snake_case singular model id (matches Go `CanonicalizeModelName`).
*/
declare function canonicalizeModelName(raw: string): string;
/** lowerCamel from canonical snake (`food_order` → `foodOrder`). */
declare function camelFromCanonical(canonical: string): string;
/** PascalCase without underscores (`food_order` → `FoodOrder`). */
declare function pascalFromCanonical(canonical: string): string;
/** Legacy camel id → Pascal (`foodCategory` → `FoodCategory`). */
declare function pascalFromAnyModelId(modelId: string): string;
declare function listGraphQLTypeName(modelId: string): string;
/** Matches Go `GraphQLComposedTypeName` (e.g. `Create_Payload`, `List_Upsert_Payload`). */
declare function apitoGraphQLComposedTypeName(modelId: string, suffix: string): string;
/**
* lowerCamel field id for GraphQL root fields — matches Go `utility.SingularResourceName`:
* trim `List` / `ListCount`, then camel-case the remainder (`CamelFromAny`), **without**
* English plural→singular inflection (that diverged from the engine and broke variable types).
*/
declare function apitoSingularResourceName(name: string): string;
declare const apitoModelName: typeof apitoSingularResourceName;
declare function apitoMultipleResourceName(name: string): string;
/**
* Public GraphQL field name for a **relation** on list/getOne rows (matches engine `attachConnectionFields`):
* - **has_many** → `{singular}List` (e.g. model `food` → `foodList`), **not** `food`.
* - **has_one** → lowerCamel singular (e.g. `customer`, `foodCategory`).
*
* Use this for `meta.connectionFields` **keys** so the generated selection matches the schema.
*/
declare function apitoConnectionFieldNameForRelation(relatedModelRef: string, relation: 'has_one' | 'has_many'): string;
/**
* Maps `meta.connectionFields` / `aliasFields` keys and targets to engine GraphQL field names.
* Unlike {@link apitoSingularResourceName} alone, this does **not** strip a trailing `List` from
* connection field ids such as **`foodList`** (that strip is for list *operation* names like `foodOrderList` → `foodOrder`).
*/
declare function apitoGraphqlConnectionFieldFromMetaKey(key: string): string;
declare function apitoGraphQLTypeNameForFilterArg(modelId: string): string;
declare function apitoListGraphQLTypeName(resource: string): string;
declare function apitoListCountGraphQLTypeName(resource: string): string;
declare function apitoSingularGraphQLTypeName(resource: string): string;
/**
* Stored model id as snake_case (matches engine `Connection.Model` / filter `definedModel.Name`).
* Use this when building mutation `connect` / `disconnect` keys: `{storedId}_id` / `{storedId}_ids`.
*/
declare function apitoStoredSnakeModelId(resource: string): string;
/** `connect` / `disconnect` field for a has_one relation: `{stored_model_id}_id` (e.g. `food_category_id`). */
declare function apitoMutationConnectHasOneIdField(relatedModelRef: string): string;
/** `connect` / `disconnect` field for a has_many relation: `{stored_model_id}_ids`. */
declare function apitoMutationConnectHasManyIdsField(relatedModelRef: string): string;
declare function apitoConnectionFilterConditionType(resource: string): string;
declare function apitoWhereRelationFilterConditionType(resource: string): string;
/**
* List query `where` / sort / `_key` payload types for `*List` fields (e.g. `FOODORDERLIST_INPUT_WHERE_PAYLOAD`).
* Do **not** use this for `*ListCount` — use {@link apitoListCountWhereInputType} / {@link apitoListCountSortInputType}.
*/
declare function apitoWhereInputType(resource: string): string;
declare function apitoSortInputType(resource: string): string;
declare function apitoListKeyConditionType(resource: string): string;
declare function apitoListCountKeyConditionType(resource: string): string;
/**
* `*ListCount` query `where` argument type (e.g. `FOOD_ORDER_LIST_COUNT_INPUT_WHERE_PAYLOAD`).
* This is **not** `FoodOrderList` + `_Count_*` (wrong: `FOODORDERLIST_COUNT_*`); the engine uses
* {@link apitoGraphQLComposedTypeName} with suffix `List_Count` (underscores between word segments).
*/
declare function apitoListCountWhereInputType(resource: string): string;
/** `*ListCount` query `sort` argument type (e.g. `FOOD_ORDER_LIST_COUNT_INPUT_SORT_PAYLOAD`). */
declare function apitoListCountSortInputType(resource: string): string;
/**
* Builds nested relation field lines for list/getOne GraphQL selection sets.
* Normalizes stored snake_case ids and legacy names to the same lowerCamel field names as the Apito engine
* (`apitoSingularResourceName`), so `aliasFields: { foodCategory: "food_category" }` still resolves to `foodCategory`.
*
* - `connectionFields` keys are the **client/response key** when `aliasFields` is set; otherwise the key is
* normalized to the schema field name.
* - `aliasFields[key]` when present is the **schema field name** (may be legacy `food_category`); it is normalized.
* - **has_many** relations use **`{model}List`** on the parent type (e.g. `foodList`), not the singular `food`.
* Use {@link apitoConnectionFieldNameForRelation}(..., `'has_many'`) or {@link apitoMultipleResourceName} for keys.
* Keys like `foodList` are preserved (see {@link apitoGraphqlConnectionFieldFromMetaKey}).
*/
declare function formatApitoConnectionSubselections(connectionFields: Record<string, string>, aliasFields?: Record<string, string>): string;
declare function buildApitoCreateMutation(resource: string, fields: string[]): string;
export { apitoConnectionFieldNameForRelation, apitoConnectionFilterConditionType, apitoGraphQLComposedTypeName, apitoGraphQLTypeNameForFilterArg, apitoGraphqlConnectionFieldFromMetaKey, apitoListCountGraphQLTypeName, apitoListCountKeyConditionType, apitoListCountSortInputType, apitoListCountWhereInputType, apitoListGraphQLTypeName, apitoListKeyConditionType, apitoModelName, apitoMultipleResourceName, apitoMutationConnectHasManyIdsField, apitoMutationConnectHasOneIdField, apitoSingularGraphQLTypeName, apitoSingularResourceName, apitoSortInputType, apitoStoredSnakeModelId, apitoWhereInputType, apitoWhereRelationFilterConditionType, buildApitoCreateMutation, camelFromCanonical, canonicalizeModelName, formatApitoConnectionSubselections, listGraphQLTypeName, pascalFromAnyModelId, pascalFromCanonical };