// Generated by AshTypescript - RPC Actions // Do not edit this file manually import type { AshRpcError, ConditionalPaginatedResultMixed, InferResult, SortString, UUID, UnifiedFieldSelection, ValidationResult, followsFilterInput, followsResourceSchema, followsSortField, mediaFilterInput, mediaResourceSchema, mediaSortField, tweetsFilterInput, tweetsResourceSchema, tweetsSortField, usersFilterInput, usersResourceSchema, usersSortField } from "./ash_types"; export type * from "./ash_types"; // Helper Functions /** * Configuration options for action RPC requests */ export interface ActionConfig { // Request data input?: Record; identity?: any; fields?: Array>; // Field selection filter?: Record; // Filter options (for reads) sort?: string | string[]; // Sort options page?: | { // Offset-based pagination limit?: number; offset?: number; count?: boolean; } | { // Keyset pagination limit?: number; after?: string; before?: string; }; // Metadata metadataFields?: ReadonlyArray; // HTTP customization headers?: Record; // Custom headers fetchOptions?: RequestInit; // Fetch options (signal, cache, etc.) customFetch?: ( input: RequestInfo | URL, init?: RequestInit, ) => Promise; // Multitenancy tenant?: string; // Tenant parameter // Hook context hookCtx?: Record; } /** * Configuration options for validation RPC requests */ export interface ValidationConfig { // Request data input?: Record; // HTTP customization headers?: Record; fetchOptions?: RequestInit; customFetch?: ( input: RequestInfo | URL, init?: RequestInit, ) => Promise; // Hook context hookCtx?: Record; } /** * Gets the CSRF token from the page's meta tag * Returns null if no CSRF token is found */ export function getPhoenixCSRFToken(): string | null { return document ?.querySelector("meta[name='csrf-token']") ?.getAttribute("content") || null; } /** * Builds headers object with CSRF token for Phoenix applications * Returns headers object with X-CSRF-Token (if available) */ export function buildCSRFHeaders(headers: Record = {}): Record { const csrfToken = getPhoenixCSRFToken(); if (csrfToken) { headers["X-CSRF-Token"] = csrfToken; } return headers; } /** * Internal helper function for making action RPC requests * Handles hooks, request configuration, fetch execution, and error handling * @param config Configuration matching ActionConfig */ export async function executeActionRpcRequest( payload: Record, config: ActionConfig ): Promise { const processedConfig = config; const headers: Record = { "Content-Type": "application/json", ...processedConfig.headers, ...config.headers, }; const fetchFunction = config.customFetch || processedConfig.customFetch || fetch; const fetchOptions: RequestInit = { ...processedConfig.fetchOptions, ...config.fetchOptions, method: "POST", headers, body: JSON.stringify(payload), }; const response = await fetchFunction("/rpc/run", fetchOptions); const result = response.ok ? await response.json() : null; if (!response.ok) { return { success: false, errors: [ { type: "network_error", message: `Network request failed: ${response.statusText}`, shortMessage: "Network error", vars: { statusCode: response.status, statusText: response.statusText }, fields: [], path: [], details: { statusCode: response.status } } ], } as T; } return result as T; } /** * Internal helper function for making validation RPC requests * Handles hooks, request configuration, fetch execution, and error handling * @param config Configuration matching ValidationConfig */ export async function executeValidationRpcRequest( payload: Record, config: ValidationConfig ): Promise { const processedConfig = config; const headers: Record = { "Content-Type": "application/json", ...processedConfig.headers, ...config.headers, }; const fetchFunction = config.customFetch || processedConfig.customFetch || fetch; const fetchOptions: RequestInit = { ...processedConfig.fetchOptions, ...config.fetchOptions, method: "POST", headers, body: JSON.stringify(payload), }; const response = await fetchFunction("/rpc/validate", fetchOptions); const result = response.ok ? await response.json() : null; if (!response.ok) { return { success: false, errors: [ { type: "network_error", message: `Network request failed: ${response.statusText}`, shortMessage: "Network error", vars: { statusCode: response.status, statusText: response.statusText }, fields: [], path: [], details: { statusCode: response.status } } ], } as T; } return result as T; } export type FollowUserInput = { followingId: UUID; }; export type FollowUserFields = UnifiedFieldSelection[]; export type InferFollowUserResult< Fields extends FollowUserFields | undefined, > = InferResult; export type FollowUserResult = | { success: true; data: InferFollowUserResult; } | { success: false; errors: AshRpcError[]; } ; /** * Create a new Follow * * @ashActionType :create */ export async function followUser( config: { tenant?: string; input: FollowUserInput; fields?: Fields; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise> { const payload = { action: "follow_user", ...(config.tenant !== undefined && { tenant: config.tenant }), input: config.input, ...(config.fields !== undefined && { fields: config.fields }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Create a new Follow * * @ashActionType :create * @validation true */ export async function validateFollowUser( config: { tenant?: string; input: FollowUserInput; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "follow_user", ...(config.tenant !== undefined && { tenant: config.tenant }), input: config.input }; return executeValidationRpcRequest( payload, config ); } export type ReadFollowFields = UnifiedFieldSelection[]; export type InferReadFollowResult< Fields extends ReadFollowFields | undefined, Page extends ReadFollowConfig["page"] = undefined > = ConditionalPaginatedResultMixed>, { results: Array>; hasMore: boolean; limit: number; offset: number; count?: number | null; type: "offset"; }, { results: Array>; hasMore: boolean; limit: number; after: string | null; before: string | null; previousPage: string; nextPage: string; count?: number | null; type: "keyset"; }>; export type ReadFollowConfig = { tenant?: string; fields: ReadFollowFields; filter?: followsFilterInput; sort?: SortString | SortString[]; page?: ( { limit?: number; offset?: number; count?: boolean; } | { limit?: number; after?: string; before?: string; } ); headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; }; export type ReadFollowResult = | { success: true; data: InferReadFollowResult; } | { success: false; errors: AshRpcError[]; } ; /** * Read Follow records * * @ashActionType :read */ export async function readFollow( config: Config & { fields: Fields } ): Promise> { const payload = { action: "read_follow", ...(config.tenant !== undefined && { tenant: config.tenant }), ...(config.fields !== undefined && { fields: config.fields }), ...(config.filter && { filter: config.filter }), ...(config.sort && { sort: Array.isArray(config.sort) ? config.sort.join(",") : config.sort }), ...(config.page && { page: config.page }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Read Follow records * * @ashActionType :read * @validation true */ export async function validateReadFollow( config: { tenant?: string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "read_follow", ...(config.tenant !== undefined && { tenant: config.tenant }) }; return executeValidationRpcRequest( payload, config ); } export type UnfollowUserInput = { followingId: UUID; }; export type InferUnfollowUserResult = {}; export type UnfollowUserResult = | { success: true; data: InferUnfollowUserResult; } | { success: false; errors: AshRpcError[]; } ; /** * Execute generic action on Follow * * @ashActionType :action */ export async function unfollowUser( config: { tenant?: string; input: UnfollowUserInput; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "unfollow_user", ...(config.tenant !== undefined && { tenant: config.tenant }), input: config.input }; return executeActionRpcRequest( payload, config ); } /** * Validate: Execute generic action on Follow * * @ashActionType :action * @validation true */ export async function validateUnfollowUser( config: { tenant?: string; input: UnfollowUserInput; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "unfollow_user", ...(config.tenant !== undefined && { tenant: config.tenant }), input: config.input }; return executeValidationRpcRequest( payload, config ); } export type ReadUserFields = UnifiedFieldSelection[]; export type InferReadUserResult< Fields extends ReadUserFields | undefined, Page extends ReadUserConfig["page"] = undefined > = ConditionalPaginatedResultMixed>, { results: Array>; hasMore: boolean; limit: number; offset: number; count?: number | null; type: "offset"; }, { results: Array>; hasMore: boolean; limit: number; after: string | null; before: string | null; previousPage: string; nextPage: string; count?: number | null; type: "keyset"; }>; export type ReadUserConfig = { tenant?: string; fields: ReadUserFields; filter?: usersFilterInput; sort?: SortString | SortString[]; page?: ( { limit?: number; offset?: number; count?: boolean; } | { limit?: number; after?: string; before?: string; } ); headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; }; export type ReadUserResult = | { success: true; data: InferReadUserResult; } | { success: false; errors: AshRpcError[]; } ; /** * Read User records * * @ashActionType :read */ export async function readUser( config: Config & { fields: Fields } ): Promise> { const payload = { action: "read_user", ...(config.tenant !== undefined && { tenant: config.tenant }), ...(config.fields !== undefined && { fields: config.fields }), ...(config.filter && { filter: config.filter }), ...(config.sort && { sort: Array.isArray(config.sort) ? config.sort.join(",") : config.sort }), ...(config.page && { page: config.page }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Read User records * * @ashActionType :read * @validation true */ export async function validateReadUser( config: { tenant?: string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "read_user", ...(config.tenant !== undefined && { tenant: config.tenant }) }; return executeValidationRpcRequest( payload, config ); } export type ReadMediaFields = UnifiedFieldSelection[]; export type InferReadMediaResult< Fields extends ReadMediaFields | undefined, Page extends ReadMediaConfig["page"] = undefined > = ConditionalPaginatedResultMixed>, { results: Array>; hasMore: boolean; limit: number; offset: number; count?: number | null; type: "offset"; }, { results: Array>; hasMore: boolean; limit: number; after: string | null; before: string | null; previousPage: string; nextPage: string; count?: number | null; type: "keyset"; }>; export type ReadMediaConfig = { tenant?: string; fields: ReadMediaFields; filter?: mediaFilterInput; sort?: SortString | SortString[]; page?: ( { limit?: number; offset?: number; count?: boolean; } | { limit?: number; after?: string; before?: string; } ); headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; }; export type ReadMediaResult = | { success: true; data: InferReadMediaResult; } | { success: false; errors: AshRpcError[]; } ; /** * Read Media records * * @ashActionType :read */ export async function readMedia( config: Config & { fields: Fields } ): Promise> { const payload = { action: "read_media", ...(config.tenant !== undefined && { tenant: config.tenant }), ...(config.fields !== undefined && { fields: config.fields }), ...(config.filter && { filter: config.filter }), ...(config.sort && { sort: Array.isArray(config.sort) ? config.sort.join(",") : config.sort }), ...(config.page && { page: config.page }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Read Media records * * @ashActionType :read * @validation true */ export async function validateReadMedia( config: { tenant?: string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "read_media", ...(config.tenant !== undefined && { tenant: config.tenant }) }; return executeValidationRpcRequest( payload, config ); } export type CreateTweetInput = { content: string; mediaId?: UUID; }; export type CreateTweetFields = UnifiedFieldSelection[]; export type InferCreateTweetResult< Fields extends CreateTweetFields | undefined, > = InferResult; export type CreateTweetResult = | { success: true; data: InferCreateTweetResult; } | { success: false; errors: AshRpcError[]; } ; /** * Create a new Tweet * * @ashActionType :create */ export async function createTweet( config: { tenant?: string; input: CreateTweetInput; fields?: Fields; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise> { const payload = { action: "create_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), input: config.input, ...(config.fields !== undefined && { fields: config.fields }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Create a new Tweet * * @ashActionType :create * @validation true */ export async function validateCreateTweet( config: { tenant?: string; input: CreateTweetInput; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "create_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), input: config.input }; return executeValidationRpcRequest( payload, config ); } export type DestroyTweetResult = | { success: true; data: {}; } | { success: false; errors: AshRpcError[]; } ; /** * Delete a Tweet * * @ashActionType :destroy */ export async function destroyTweet( config: { tenant?: string; identity: UUID; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "destroy_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity }; return executeActionRpcRequest( payload, config ); } /** * Validate: Delete a Tweet * * @ashActionType :destroy * @validation true */ export async function validateDestroyTweet( config: { tenant?: string; identity: UUID | string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "destroy_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity }; return executeValidationRpcRequest( payload, config ); } export type LikeTweetFields = UnifiedFieldSelection[]; export type InferLikeTweetResult< Fields extends LikeTweetFields | undefined, > = InferResult; export type LikeTweetResult = | { success: true; data: InferLikeTweetResult; } | { success: false; errors: AshRpcError[]; } ; /** * Update an existing Tweet * * @ashActionType :update */ export async function likeTweet( config: { tenant?: string; identity: UUID; fields?: Fields; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise> { const payload = { action: "like_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity, ...(config.fields !== undefined && { fields: config.fields }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Update an existing Tweet * * @ashActionType :update * @validation true */ export async function validateLikeTweet( config: { tenant?: string; identity: UUID | string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "like_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity }; return executeValidationRpcRequest( payload, config ); } export type ReadFollowingFeedFields = UnifiedFieldSelection[]; export type InferReadFollowingFeedResult< Fields extends ReadFollowingFeedFields, > = Array>; export type ReadFollowingFeedResult = | { success: true; data: InferReadFollowingFeedResult; } | { success: false; errors: AshRpcError[]; } ; /** * Read Tweet records * * @ashActionType :read */ export async function readFollowingFeed( config: { tenant?: string; fields: Fields; filter?: tweetsFilterInput; sort?: SortString | SortString[]; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise> { const payload = { action: "read_following_feed", ...(config.tenant !== undefined && { tenant: config.tenant }), ...(config.fields !== undefined && { fields: config.fields }), ...(config.filter && { filter: config.filter }), ...(config.sort && { sort: Array.isArray(config.sort) ? config.sort.join(",") : config.sort }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Read Tweet records * * @ashActionType :read * @validation true */ export async function validateReadFollowingFeed( config: { tenant?: string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "read_following_feed", ...(config.tenant !== undefined && { tenant: config.tenant }) }; return executeValidationRpcRequest( payload, config ); } export type ReadTweetFields = UnifiedFieldSelection[]; export type InferReadTweetResult< Fields extends ReadTweetFields | undefined, Page extends ReadTweetConfig["page"] = undefined > = ConditionalPaginatedResultMixed>, { results: Array>; hasMore: boolean; limit: number; offset: number; count?: number | null; type: "offset"; }, { results: Array>; hasMore: boolean; limit: number; after: string | null; before: string | null; previousPage: string; nextPage: string; count?: number | null; type: "keyset"; }>; export type ReadTweetConfig = { tenant?: string; fields: ReadTweetFields; filter?: tweetsFilterInput; sort?: SortString | SortString[]; page?: ( { limit?: number; offset?: number; count?: boolean; } | { limit?: number; after?: string; before?: string; } ); headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; }; export type ReadTweetResult = | { success: true; data: InferReadTweetResult; } | { success: false; errors: AshRpcError[]; } ; /** * Read Tweet records * * @ashActionType :read */ export async function readTweet( config: Config & { fields: Fields } ): Promise> { const payload = { action: "read_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), ...(config.fields !== undefined && { fields: config.fields }), ...(config.filter && { filter: config.filter }), ...(config.sort && { sort: Array.isArray(config.sort) ? config.sort.join(",") : config.sort }), ...(config.page && { page: config.page }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Read Tweet records * * @ashActionType :read * @validation true */ export async function validateReadTweet( config: { tenant?: string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "read_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }) }; return executeValidationRpcRequest( payload, config ); } export type UnlikeTweetFields = UnifiedFieldSelection[]; export type InferUnlikeTweetResult< Fields extends UnlikeTweetFields | undefined, > = InferResult; export type UnlikeTweetResult = | { success: true; data: InferUnlikeTweetResult; } | { success: false; errors: AshRpcError[]; } ; /** * Update an existing Tweet * * @ashActionType :update */ export async function unlikeTweet( config: { tenant?: string; identity: UUID; fields?: Fields; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise> { const payload = { action: "unlike_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity, ...(config.fields !== undefined && { fields: config.fields }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Update an existing Tweet * * @ashActionType :update * @validation true */ export async function validateUnlikeTweet( config: { tenant?: string; identity: UUID | string; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "unlike_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity }; return executeValidationRpcRequest( payload, config ); } export type UpdateTweetInput = { content?: string; }; export type UpdateTweetFields = UnifiedFieldSelection[]; export type InferUpdateTweetResult< Fields extends UpdateTweetFields | undefined, > = InferResult; export type UpdateTweetResult = | { success: true; data: InferUpdateTweetResult; } | { success: false; errors: AshRpcError[]; } ; /** * Update an existing Tweet * * @ashActionType :update */ export async function updateTweet( config: { tenant?: string; identity: UUID; input: UpdateTweetInput; fields?: Fields; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise> { const payload = { action: "update_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity, input: config.input, ...(config.fields !== undefined && { fields: config.fields }) }; return executeActionRpcRequest>( payload, config ); } /** * Validate: Update an existing Tweet * * @ashActionType :update * @validation true */ export async function validateUpdateTweet( config: { tenant?: string; identity: UUID | string; input: UpdateTweetInput; headers?: Record; fetchOptions?: RequestInit; customFetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise; } ): Promise { const payload = { action: "update_tweet", ...(config.tenant !== undefined && { tenant: config.tenant }), identity: config.identity, input: config.input }; return executeValidationRpcRequest( payload, config ); }